第三个bug根本没遇到 而第一二个bug和默认显示第一张图片

来源:7-2 揭秘案例bug值解决第三个bug

WebSaber

2019-09-22 18:31:20

$(document).ready(function() {
    var index = 0;
    var swiper = function() {
        $('img').eq(index).css({ 'opacity': '1' }).siblings().css({ 'opacity': '0' });
    }
    $(document).on('mouseenter','a',function(){
        index=$(this).index();
        swiper();
    })
    $(document).on('keydown',function () { 
        if (event.keyCode == 37) {
            if(index==0){
                index=$("a").length-1;
            }else{
                index --;
            }
            swiper();
        } else if (event.keyCode == 39) {
            if(index==$("a").length-1){
                index=0;
            }else{
                index ++;
            }
            swiper();
        }
    });
});

//
//
//第三个bug根本没遇到 而第一二个bug和默认显示第一张图片
//只需要在第一个img加个z-index就全部解决了
 <img src="images/1.jpg" style="z-index: 999">


写回答

1回答

樱桃小胖子

2019-09-23

代码是灵活的,解决办法也是不同的哦,并且同学的代码跟老师的代码有一定的出入,所以按照同学的写法可能是没有第三种bug的,但是在老师的代码中是会出现第三种bug的哦

希望可以帮到你!

0

0 学习 · 14456 问题

查看课程