滚动垂直真的很慢

时间:2014-03-26 18:25:44

标签: javascript jquery scroll switch-statement

我有一个问题,当我启动滚动功能2次时,好吧,在滚动3次点击后开始放慢功能 为什么?我该如何解决?

我的JS:

 $(document).ready(function () {
    var scroll = true;
    jQuery(window).bind('mousewheel', function (event) {
        if (!scroll) {
            event.preventDefault();
        }
    })



    $('form#slider img.img').click(function () {


      //-------GET IMAGES FROM LOCALARRAY--------//

        var index = $(this).prevAll('img').length; // to get the length of prev images.
        $('div#immagini img').attr('src', imgArray[index]);
        scopri(0);

      //-------ANIMATION DOWN--------//

        scroll = false;
        $('html, body').animate({
            scrollTop: '700px'
        }, 1500, function () {
            scroll = true
        });

        var conta=0;


        switch (index) {

            case 0:

                //-----LOAD QUESTION FROM ARRAY-----//
                document.getElementById("domande").getElementsByTagName('p')[0].innerText = domArray[0];

                //-----LOAD ANSWER FROM HTML-----//
                document.getElementById("risp0").style.display = "block";
                document.getElementById("risp1").style.display = "none";


                $("#ris3").click(function () {

                    $('div#immagini img').attr('src', giuArray[0]);

                  //-----ANIMATE TOP-----//
                    scroll = false;
                    $('html, body').animate({
                        scrollTop: '0px'
                    }, 2000, function () {
                        scroll = true

                    });
                });

                $("#ris1").click(function () {

                    $('div#immagini img').attr('src', errArray[0]);

                  //-----ANIMATE TOP-----//
                    scroll = false;
                    $('html, body').animate({
                        scrollTop: '0px'
                    }, 2000, function () {
                        scroll = true
                    });
                });

                $("#ris2").click(function () {

                    $('div#immagini img').attr('src', errArray[0]);

                  //-----ANIMATE TOP-----//
                    scroll = false;
                    $('html, body').animate({
                        scrollTop: '0px'
                    }, 2000, function () {
                        scroll = true
                    });
                });
                break;
            case 1:

                document.getElementById("risp1").style.display = "block";
                document.getElementById("risp0").style.display = "none";


                $("#ris4").click(function () {
                    $('div#immagini img').attr('src', giuArray[1])

                  //-----ANIMATE TOP-----//

                    scroll = false;
                    $('html, body').animate({
                        scrollTop: '0px'
                    }, 2000, function () {
                        scroll = true
                    });
                });
                $("#ris5").click(function () {
                    $('div#immagini img').attr('src', errArray[1]);

                  //-----ANIMATE TOP-----//

                    scroll = false;
                    $('html, body').animate({
                        scrollTop: '0px'
                    }, 2000, function () {
                        scroll = true
                    });
                });

                $("#ris6").click(function () {

                    $('div#immagini img').attr('src', errArray[1]);

                  //-----ANIMATE TOP-----//

                    scroll = false;
                    $('html, body').animate({
                        scrollTop: '0px'
                    }, 2000, function () {
                        scroll = true
                    });
                });
                break;

        }
    });

我认为与Switch(索引)存在冲突; 请帮帮我,两天我都会失去理智。:)

0 个答案:

没有答案