admin管理员组

文章数量:1430093

I'm using swiper.js and once swiper1.destroy(); run, rebuild, slide to a certain slide and click.

I got error of swiper.js:438 Uncaught TypeError: Cannot read property 'params' of null

Here's the code. I appreciate all helps. Thank you very much.

$('.call').click(function(e){
e.preventDefault()

$("#menu").addClass("hide");
$("#slider").removeClass("hide");

selector.push("address");

var swiper1 = new Swiper('.swiper1', {
    pagination: '.one',
    paginationClickable: true,
    hashnav: true,
    loop:true,
    initialSlide:0
});

getLocation();

$('.noclick').click(function(e){
    e.preventDefault()
    swiper1.unlockSwipes(); // <-- This seems to be causing the problem
    swiper1.slidePrev(); // <-- This seems to be causing the problem
    player.seekTo(0);
})

$('.yes').click(function(e){
    e.preventDefault()
    swiper1.unlockSwipes(); // <-- This seems to be causing the problem
    swiper1.slideNext(); // <-- This seems to be causing the problem
})

$('.overlay').click(function(e){
    swiper1.unlockSwipes();
    console.log("overlay");
    e.preventDefault()
    $("#menu").removeClass("hide");
    $("#slider").addClass("hide");
    swiper1.destroy();
})

swiper1.on('slideChangeStart', function () {
    var dataindex = $(".swiper-slide-active").data('index');
    console.log(dataindex);

    if(dataindex == 8){
        onPlayerReady();
        swiper1.lockSwipes();
        setTimeout(function(){
            //var state = player.getPlayerState();
            //console.log(state);
            //if (state == 0){
                //alert("This should work");
                swiper1.unlockSwipes();
                swiper1.slideTo(9);
            //}
        },4000);

    }else if(dataindex == 9) {  
        swiper1.lockSwipes();
    }else if(dataindex == 10){
        swiper1.lockSwipes();
    }else{
        stopVideo();
    }
});

})

I'm using swiper.js and once swiper1.destroy(); run, rebuild, slide to a certain slide and click.

I got error of swiper.js:438 Uncaught TypeError: Cannot read property 'params' of null

Here's the code. I appreciate all helps. Thank you very much.

$('.call').click(function(e){
e.preventDefault()

$("#menu").addClass("hide");
$("#slider").removeClass("hide");

selector.push("address");

var swiper1 = new Swiper('.swiper1', {
    pagination: '.one',
    paginationClickable: true,
    hashnav: true,
    loop:true,
    initialSlide:0
});

getLocation();

$('.noclick').click(function(e){
    e.preventDefault()
    swiper1.unlockSwipes(); // <-- This seems to be causing the problem
    swiper1.slidePrev(); // <-- This seems to be causing the problem
    player.seekTo(0);
})

$('.yes').click(function(e){
    e.preventDefault()
    swiper1.unlockSwipes(); // <-- This seems to be causing the problem
    swiper1.slideNext(); // <-- This seems to be causing the problem
})

$('.overlay').click(function(e){
    swiper1.unlockSwipes();
    console.log("overlay");
    e.preventDefault()
    $("#menu").removeClass("hide");
    $("#slider").addClass("hide");
    swiper1.destroy();
})

swiper1.on('slideChangeStart', function () {
    var dataindex = $(".swiper-slide-active").data('index');
    console.log(dataindex);

    if(dataindex == 8){
        onPlayerReady();
        swiper1.lockSwipes();
        setTimeout(function(){
            //var state = player.getPlayerState();
            //console.log(state);
            //if (state == 0){
                //alert("This should work");
                swiper1.unlockSwipes();
                swiper1.slideTo(9);
            //}
        },4000);

    }else if(dataindex == 9) {  
        swiper1.lockSwipes();
    }else if(dataindex == 10){
        swiper1.lockSwipes();
    }else{
        stopVideo();
    }
});

})
Share Improve this question edited Jan 6, 2016 at 5:06 Eggsnuff asked Jan 6, 2016 at 4:52 EggsnuffEggsnuff 391 gold badge1 silver badge8 bronze badges 1
  • At what point you get the error? Be specific. – Mangesh Commented Jan 6, 2016 at 4:53
Add a ment  | 

1 Answer 1

Reset to default 1

I got similar error and I was need to properly remove old event listener on swiper.destroy() and attach new one since previous was refer to destroyed object.

In my case it looks like this

// on init
window.addEventListener('keydown', this.handleKeypressFn)

..
// than somewhere before destroy()
window.removeEventListener('keydown', this.handleKeypressFn)
swiper1.destroy()

本文标签: javascriptSwiperjsUncaught TypeError Cannot read property 39params39 of nullStack Overflow