hover事件具有两个回调
$( ele ).hover(infunction,outfunction);
//相当于
$( ele ).mouseenter( infunction ).mouseleave( outfunction);
//infunction:光标进入元素后的回调函数
//outfuntion:光标出去元素后的回调函数
举例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hover</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("p").hover(function(){
$("p").css("background-color","red");
},function(){
$("p").css("background-color","pink");
});
});
</script>
</head>
<body>
<p>悬浮事件添加区域</p>
</body>
</html>
该文章介绍了jQuery中hover事件的使用,它结合了mouseenter和mouseleave两个回调函数。当光标进入元素时,infunction执行,将段落背景色改为红色;离开元素时,outfunction执行,背景色恢复为粉色。示例展示了hover事件如何操作CSS属性。
858

被折叠的 条评论
为什么被折叠?



