document绑定的moveenter事件
来源:7-2 揭秘案例bug值解决第三个bug
weixin_慕仰4083625
2019-09-22 10:23:38
$(document).ready(function(){
var index = 0;
$("a").add(document).on({
mouseenter:function(event){
console.log(event);
event.stopPropagation();
index = $(this).index();
swiper();
},
keydown:function(event){
event.stopPropagation();
index = index > 0?--index:$('a').length-1;
}else if (event.keyCode==39) {
index = index < $('a').length-1?++index:0;
}else {
return true;
}
swiper();
}
});
var swiper = function(){
$('img').eq(index).css({'opacity':'1'}).siblings().css({'opacity':'0'});
}
});这边为什么触发document绑定的moveenter事件(从外面回到页面内部)图片就会变成最后一张,触发document绑定的moveenter事件的index = $(this).index();这条语句的index赋值多少呢?
2回答
樱桃小胖子
2019-09-23
这个时候index是-1,检测如下:


希望可以帮到你!
樱桃小胖子
2019-09-23
在本节课程中老师有讲解从外面回到页面内部,图片就会变成最后一张的原因哦。同学可以从视频2分钟处开始再听一下视频哦,index = $(this).index();表示的是当前的元素的index
希望可以帮到你!
相似问题