onmouseover 和 onmouseenter

onmouseover 和 onmouseenter

这两个有什么不同呀  我自己做了下  mouseenter就好了 mouseover不行

var autoplayfn=setInterval(function () {

index++;

console.log(index)

tip.removeClass('item_focus');

tip.eq(index).addClass('item_focus')

wrap.css({'left':-(index*width)})

if(index>size-1){

index=0;

tip.eq(index).addClass('item_focus')

wrap.css({'left':-(index*width)})

}},1000)



ui.on('mouseenter',function () {

clearInterval(autoplayfn)

})

.on('mouseleave',function () {

    autoplayfn=setInterval(function () {

index++;

console.log(index)

tip.removeClass('item_focus');

tip.eq(index).addClass('item_focus')

wrap.css({'left':-(index*width)})

if(index>size-1){

index=0;

tip.eq(index).addClass('item_focus')

wrap.css({'left':-(index*width)})

}},1000)

})


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕星星 2020-06-18 11:11:29

同学你好,这两个事件的区别就是mouseover会事件冒泡,如果父元素也有这个事件,会向上冒泡触发的。例如:

http://img1.sycdn.imooc.com//climg/5eeada990922d59f08740474.jpghttp://img1.sycdn.imooc.com//climg/5eeadaca0973369d07300909.jpg

mouseenter是不会向上冒泡的。

但是同学的这段代码老师粘贴到源码中测试,mouseenter和mouseover事件都是可以的,移入的时候定时器会停止。

不知道同学是怎样布局的,建议再测试下,如果还是有问题,建议将html以及css代码全部粘贴上来,老师帮助测试。

祝学习愉快!

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
2.组件化网页开发
  • 参与学习           人
  • 提交作业       1121    份
  • 解答问题       14456    个

本阶段在运用JS实现动态网页开发的基础上,带你深入理解企业开发核心思想,完成一个企业级网页的开发,体验前端工程师的成就感。

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师