我觉得第三个bug有问题
来源:7-2 揭秘案例bug值解决第三个bug
慕标5156652
2020-07-11 18:29:00
按照视频里老师那样写 是会出现 老师提及的那种问题
如果按照前面老师说如下 如下 就不会出现这种问题
var index =$("a").length-1;
$("a").mouseenter(function () {
index = $(this).index();
swiper();
});
$(document).keydown(function (event) {
console.log(event.keyCode)
if (event.keyCode == 37) {
// if (index == 0) {
// index = $("a").length - 1;
// } else {
// index = index - 1;
// }
index=index>0?--index:$("a").length-1;
// swiper();
} else if (event.keyCode == 39) {
// if (index == $("a").length - 1) {
// index = 0;
// } else {
// index = index+1;
// }
index=index<$("a").length-1?++index:0;
// swiper();
}else{
return
}
swiper();
});
var swiper = function () {
$("img").eq(index).css({ "opacity": '1' }).siblings().css({ "opacity": '0' });
}
1回答
好帮手慕久久
2020-07-11
同学你好,是这样的。代码的书写方式不同,可能会出现不同的bug,也可能会解决其他写法出现的某些bug,这是正常的现象,同学了解下就行。
祝学习愉快!