写得不好的jQuery正在崩溃浏览器

Badly written jQuery that is crashing browser

本文关键字:崩溃 浏览器 jQuery      更新时间:2023-09-26

我正在使用一个名为Background stretcher的jQuery插件,这是启动它的代码。我在回调函数中按下链接的次数越多,网站就会开始挂起,所以有没有更好的写法......

$(document).ready(function(){
    //  Initialize Backgound Stretcher     
    $('BODY').bgStretcher({
        images: ['images/exterior.jpg', 'images/exterior2.jpg','images/kitchen.jpg','images/bathroom.jpg','images/bedroom.jpg'],
        imageWidth: 1800, 
        imageHeight: 1400, 
        slideDirection: 'N',
        slideShowSpeed: 1000,
        nextSlideDelay: 6000,
        transitionEffect: 'fade',
        sequenceMode: 'normal',
        buttonPrev: '.prev',
        buttonNext: '.next',
        pagination: '.pagination',
        anchoring: 'left center',
        anchoringImg: 'left center',
        callbackfunction: function() {
                    $('a#design').click(function(){
                        $().bgStretcher._clearTimeout();
                        $().bgStretcher.slideShow('normal', 0);
                        $().bgStretcher.play();
                    });
                    $('a#interior').click(function(){
                        $().bgStretcher._clearTimeout();
                        $().bgStretcher.slideShow('normal', 1);
                        $().bgStretcher.play();
                    });
                    $('a#lifestyle').click(function(){
                        $().bgStretcher.pause();
                        $().bgStretcher.slideShow('normal', 2);
                        $().bgStretcher.play();
                    });
                    $('a#location').click(function(){
                        $().bgStretcher.pause();
                        $().bgStretcher.slideShow('normal', 3);
                        $().bgStretcher.play();
                    });
                    $('a#contact').click(function(){
                        $().bgStretcher.pause();
                        $().bgStretcher.slideShow('normal', 4);
                        $().bgStretcher.play();
                    });
        }
    });
});
有什么更有效

/更干净的写法

而不是

$()你应该写$('body')所以尝试这样使用它:

.
.
.
//  Initialize Backgound Stretcher     
    $('body').bgStretcher({
.
.
.
.
                    $('a#design').click(function(){
                        $('body').bgStretcher._clearTimeout();
                        $('body').bgStretcher.slideShow('normal', 0);
                        $('body').bgStretcher.play();
                    });
.
.
.