Day: December 9, 2012

  • Using Nivo Slider with Prototype

    我想要一个 jQuery slider plugin 用在 Magento 上。jQuery slider 类不乏优秀的程序。我不及精挑细选,用了 Nivo Slider。

    虽然 slider 能运行,但 FireBug 停止响应。查错发现 too much recursion occured in prototype.js 1132 行。自然想到了 jQuery 和 Prototype 的 conflict,但我有做 noConflict.js,而且 jquery.nivo.slider.js 也没有在全局使用 $,看上去挺规范的呀。

    我让 Magento 暂不加载 prototype.js,too much recursion 错误就没有了,但 Magento 不能没有 prototype.js (盼望 Magento 哪天自动放弃 prototype,用 jQuery 重写)。

    我有意放弃 Nivo Slider,无意中又发现别人竟做过同样的事情——把 Nivo Slider 用在Magento 下,而且没有 javascript 错误。

    我以为是我那段 slider 的 html 写得不好,全盘拷了别人的来用,还是出错。然后我认为是版本问题,可是用别人的 jQuery 库,放在我这里,还是出错。

    最后,直到最后,我意识到一点不同之处,我用不带任何参数启动 Nivo Slider,即

    $('#slider').nivoSlider();
    

    而别人用

    	$('#slider').nivoSlider({
            effect: 'sliceDown', 
            slices: 15, 
           
            animSpeed: 500, 
            pauseTime: 3000, 
            startSlide: 0, 
    		 
            directionNav: true, 
    		        directionNavHide: true, 
    		        controlNav: true, 
                    keyboardNav: true, 
    		        pauseOnHover: true, 
                    captionOpacity: 1, 
            prevText: 'Prev', 
            nextText: 'Next' 
           
        });
    

    就这点造成了 too much recursion。