jquery的hover mouseover mouseout mouseenter mouseleave的区别
jquery的hover mouseover mouseout mouseenter mouseleave的区别
1.mouseover mouseout
mouseover - 鼠标指针经过任何子元素都会触发绑定在父元素上的mouseover事件
mouseout - 鼠标指针离开任何子元素时都会触发父元素上的mouseover事件
然后,你把代码拷贝过去try一下,就会有更深刻的理解;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
$(function (){
var outer=$("#outer");
outer.mouseover(function (){
alert('outer mouseover');
}).mouseout(function (){
alert('outer mouseout');
})
//当子元素的over 和 out事件发生时,
//事件会冒泡到父级,也就是说outer上的 over 和 out 会被触发
var inner=$("#inner");
inner.mouseover(function (){
alert('inner mouseover');
}).mouseout(function (){
alert('inner mouseout');
})
}) </script>
<style type="text/css">
.outer{
height:100px;
width:20%;
background-color:green;
float:left;
margin-left:25px;
}
.inner{
height:50px;
width:60%;
margin:25px auto;
background-color:red;
}
</style>
</head> <body>
<div id="outer" class="outer">
<div id="inner" class="inner"></div>
</div>
</body>
</html>
2.mouseenter mouseleave
mouseenter - 鼠标指针经过绑定的元素时触发事件,经过其子元素时,不会触发事件
mouseleave - 只有当鼠标离开绑定的元素时才会触发该事件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="script/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(function (){
var outer1=$("#outer1");
outer1.mouseenter(function (){
alert('outer1 mouseenter');
}).mouseleave(function (){
alert('outer1 mouseleave');
})
var inner1=$("#inner1");
inner1.mouseenter(function (){
alert('inner1 mouseenter');
}).mouseleave(function (){
alert('inner1 mouseleave');
})
}) </script>
<style type="text/css">
.outer{
height:100px;
width:20%;
background-color:green;
float:left;
margin-left:25px;
}
.inner{
height:50px;
width:60%;
margin:25px auto;
background-color:red;
}
</style>
</head> <body>
<div id="outer1" class="outer">
<div id="inner1" class="inner"></div>
</div>
</body>
</html>
houver:
hover!= mouseover+mouseout
hover=mouseenter + mouseleave
$(function (){
//我们的hover是这样定义的;
hover: function( fnOver, fnOut ) {
return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
}
})
jquery的hover mouseover mouseout mouseenter mouseleave的区别的更多相关文章
- mouseover,mouseout,mouseenter,mouseleave的区别
1.前言 今天下午参加一个面试,对方问我写不写博客,这时候才猛然意识到好久没写东西了.最近一直在外边实习,每天有很多经历和挑战,但是却没有及时地记录下来,这一点必须得批评自己,以后得经常把自己遇到的问 ...
- 关于事件mouseover ,mouseout ,mouseenter,mouseleave的区别
轮播中大多会选择mouseover和mouseout 这个时候是没有任何问题的 但当遇到有css3动画的时候,会发现移入移出过快 动画还没加载完成就需要执行下一个动画,完了动画样式就错乱了. 这时候 ...
- 你可能不知道的mouseover/mouseout mouseenter/mouseleave
mouseover与mouseenter 1. 触发时机 mouseover在被监听的节点与子节点上都会触发 mouseenter只在被监听的节点上触发 本质上是因为mouseenter不能冒泡 2. ...
- jQuery里的mouseover与mouseenter事件类型区别
JQ里面有mouseover和mouseenter 2个事件类型干着差不多的活,用不好经常出现些小问题. 今天我解释一下原理: 事件类型翻译: mouseover 鼠标移上 mouseenter 鼠 ...
- 理解mouseover,mouseout,mouseenter,mouseleave
mouseover定义和用法 当鼠标指针位于元素上方时,会发生 mouseover 事件. 该事件大多数时候会与 mouseout 事件一起使用. mouseover() 方法触发 mouseover ...
- mouseover,mouseout和mouseenter,mouseleave的区别及适用情况
在做类似于百度地图右下角,不同地图切换UI时,遇到了问题. 就是鼠标滑过的时候出现一个层,当鼠标滑到当前层的话mouseover和mouseout在低版本的浏览器会出现闪动的现象,最简单的那就是把mo ...
- jQuery mouseover与mouseenter,mouseout与mouseleave的区别
mouseover与mouseenter 不论鼠标指针穿过被选元素或其子元素,都会触发 mouseover 事件. 只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件. mouseou ...
- 曾经跳过的坑----jQuery mouseover与mouseenter,mouseout与mouseleave的区别
mouseover与mouseenter 不论鼠标指针穿过被选元素或其子元素,都会触发 mouseover 事件. 只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件. mouseou ...
- mouseover和mouseenter,mouseout和mouseleave的区别-引发的探索
相信小伙伴们都用过鼠标事件,比如mouseover和mouseout,mouseenter和mouseleave.它们都分别表示鼠标移入移出. 在使用的过程中,其实一直有个小疑问——它们之间究竟有什么 ...
随机推荐
- idea_IDEA跑Tomcat异常
IDEA跑Tomcat异常 具体异常如下 Artifact :war exploded: Server is not connected. Deploy is not avail 根据别人的回答,去掉 ...
- Redis错误配置详解
在使用Redis做缓存时,应用往往能得到非常高的性能.然而,如果配置不当,你将遇到很多令人头疼的问题,比如复制缓冲区限制.复制超时等. Redis提供了许多提高和维护高效内存数据库使用的工具.在无需额 ...
- CentOS 实现自动登陆
1. 在ssh-client一边使用ssh-keygen生成一对rsa key $ssh-keygen -t rsa 2. 在ssh-client一边使用ssh-add将刚生成的private key ...
- NSString 处理技巧:分割字符串
摘要 string类型是objective-c中用的最多的类型之一,有时会出现字符串中有我们不想要的字符. 如 "hello world"中的空格,或是"hello/wo ...
- 2015寒假ACM训练计划
1月26号至3月4号 每天给自己一个计划.做有意义的事情,不要浪费时间. 8:00——11:30 acm训练 11:30——13:00 午休 13:00——17:30 acm训练 17:30——18 ...
- Css - Table.css
基本的Table样式 .gridtable { border: solid #ccc 1px; -moz-border-radius: 6px; -webkit-border-radius: 6px; ...
- SQLServer组件
1.客户端 2.协议层 3.查询处理器 4.存储引擎 5.数据库操作系统 如下图:
- snowflake
snowflake在分布式系统中生成全局id
- AMD PerfStudio
用PerfStudio 抓DX11 OIT
- PHP 中和 HTTP 相关的函数及使用
① get_headers 方法:取得服务器响应一个 HTTP 请求所发送的所有标头 例如: <?php $httpinfo = get_headers('http://www.baidu.co ...