今天给大家带来的是jQuery的事件,事件的一些需要注意的点
一事件的种类
1鼠标事件
js事件:
鼠标移入,鼠标移出,鼠标点击,双击
onmouseover onmouseout onmousemove
onmouseleave onmouseenter
(onmoueup onmousedown)
jQuery事件就是将每个事件前的on去掉,例如:mousemove
2,键盘事件
js事件:
键盘按下,键盘松开
onkeydown onkeyup onkeypress
3.表单事件
js事件:
onsubmit表单提交事件 onreset表单重置事件
4.焦点事件
js事件:
onblur 失去 onfouse得到
5,其他事件
js事件:
onchange 输入框的值发生改变时
ondblclick双击事件
二,加载事件的两种方式
1.window.onload = () => {}
在整个页面加载完后执行
2.jQuery方式:
$(() => {})
在整个网页的结构绘制完成后执行
三,绑定事件(委托事件)
// 委托事件
$("table").on("click","button",function(){
$(this).parents("tr").remove()
})
})
// this在正常函数中是this
// this在箭头函数中是window
四,事件的切换
-
hover(鼠标悬停合成事件)
1鼠标上去第一个函数
2鼠标移出第二个函数 -
toggle(鼠标点击合成事件)
$('div').toggle(1000)"
//1000为毫秒数,一秒内执行
五,事件的传播(冒泡)
首先,事件的冒泡与传播是不一样的
// 事件的冒泡会将事件传到你的父级标签
//冒泡和传播不是一个东西
$("p").click(function(){
alert("fgsfbffasgfdf ")
return false
})
如何阻断传播,通过用return就可以了
六,事件坐标,移除事件
$("body").mousemove(e=>{
//e就是事件对象
console.log(e.clientX,e.pageX,e.offsetX)
})
$("body").unbind("mousemove")
//一般情况下,不会用unbind,推荐使用变量控制事件
//如果某个元素之允许使用一次事件,则可以使用one()
七,动画
1,基本
2,滑动
3,透明度
4,案例
//css
<style type="text/css">
div {
/* width: 100px !important; */
width: 100px ;
height: 100px;
background-color: aqua;
display: inline-block;
position: absolute;
}
</style>
//html
<div>
</div>
//js
// fade fade淡入 fadepout淡出
// $("div").fadeOut(4000)
$("div").mousemove(function (){
$(this).animate({
width:"400px",
height:"400px",
left:"100px",
top:"100px"
})
})
注意:
// this在正常函数中是this
// this在箭头函数中是window
好了,这就是今天给大家分享的内容了,留个足迹在走吧!