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.它们都分别表示鼠标移入移出. 在使用的过程中,其实一直有个小疑问——它们之间究竟有什么 ...
随机推荐
- iOS开发项目之三 [ 自定义tabBarCtrl]
01 让tabBar的图片保持原样.图片渲染的处理 ctrl.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithF ...
- [文字雲產生器] Tagxedo 把文字串成雲、變成畫,印在 T-Shirt、馬克杯、詩袋….
http://www.tagxedo.com/app.html 有種東西叫「Word Clouds」,就是把一堆文字依照不同的大小.顏色.角度與位置拼湊在一起,讓他變成像一朵雲一般.組合成各種不同的形 ...
- Javascript - 数组去重复
这里我使用的场景是将表单中所有的input的值塞入数组中,然后通过去除重复的值.如果数组的长度和原数组的长度一致,说明没有重复,如果不一致(少于)则报错 //通过$.unique对数组进行“去重”,再 ...
- Editplus从下载到使用
☆ 准备工作 1,保证浏览器正常上网 2,能下载软件或已经下载到Editplus这个工具. ☆ 下载editplus 在浏览器输入http://www.editplus.com,然后回车.进入edit ...
- SAE saestorage.class.php文件的封装代码
Source for file saestorage.class.php Documentation is available at saestorage.class.php <?php /** ...
- Oracle11g创建表空间语句
在plsql工具中执行以下语句,可建立Oracle表空间. /*分为四步 *//*第1步:创建临时表空间 */create temporary tablespace yuhang_temp temp ...
- poj2387 初涉最短路
前两天自学了一点点最短路..看起来很简单的样子... 就去kuangbin的专题找了最简单的一道题练手..然后被自己萌萌的三重for循环超时虐的不要不要的~ 松弛虽然会但是用的十分之不熟练... 代码 ...
- [办公自动化]Wlan无法启动,无法连接无线网wifi,所有无线网都搜索不到
转帖: http://support1.lenovo.com.cn/lenovo/wsi/htmls/detail_20121023172943554.html 故障现象: 启动wlan autoco ...
- Ubuntu 安装 ImageMagic(6.9.1-6)及 PHP 的 imagick (3.0.1)扩展
关于 ImageMagic 和 imagick 的介绍,见<图片处理神器ImageMagick以及PHP的imagick扩展> 和 <Ubuntu下安装ImageMagick和Mag ...
- Bootstrap页面布局17 - BS选项卡
代码结构: <div class='container-fluid'> <h2 class='page-header'>Bootstrap 选项卡</h2> < ...