Search code examples
javascriptnivo-slider

NivoSlider error


I use NivoSlider and I want to stop it after load (to start it manually).

I use the following code:

<script type="text/javascript">
    $(window).load(function() {
        $('#slider1').nivoSlider({
            effect: 'random', // Specify sets like: 'fold,fade,sliceDown'
            slices: 15, // For slice animations
            boxCols: 8, // For box animations
            boxRows: 4, // For box animations
            animSpeed: 800, // Slide transition speed
            pauseTime: 3000, // How long each slide will show
            startSlide: 0, // Set starting Slide (0 index)
            directionNav: false, // Next & Prev navigation
            controlNav: false, // 1,2,3... navigation
            controlNavThumbs: false, // Use thumbnails for Control Nav
            pauseOnHover: false, // Stop animation while hovering
            manualAdvance: false, // Force manual transitions
            paused:true,
            afterLoad: function(){
            $('#slider1').data('nivoSlider').stop();
 }
        });
    });

</script>

But I get the Error: Uncaught TypeError: Cannot read property 'stop' of undefined.


Solution

  • In afterLoad() this context it's NivoSlider. So you can call just this.stop().

    afterLoad: function() {
        this.stop();
    }