t.destroy is not a function for second call in ajax #4254
Unanswered
Gr3edIsGood
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello there!
Getting console error: Uncaught TypeError: t.destroy is not a function each time im trying to resize window.
Seems like script works fine, becouse in load it does work. Swiper arnt working untill i size it to my proper width
But the actual, i call it twice. In my 'main' page and on other pages i call it with ajax.
heres code:
let windowWidth;
const element = $('#swiper-footer-container');
const minWidth = '879';
let footerSwiper;
function loadSwiper() {
windowWidth = $(window).width();
if (!footerSwiper) {
if (windowWidth < minWidth) {
enableSwiperFooter();
console.log('good');
}
} else if (footerSwiper && windowWidth > minWidth) {
if (footerSwiper) {
footerSwiper.destroy(true, true);
footerSwiper = undefined;
console.log('bad');
}
}
}
const enableSwiperFooter = () => {
footerSwiper = new Swiper(element, {
grabCursor: true,
nextButton: '#footer-swiper-btn-next',
prevButton: '#footer-swiper-btn-prev',
slidesPerView: 1,
centeredSlides: true,
}, 1000);
};
$(window).resize(() => {
loadSwiper();
});
I call it and import into 'main.js'
Also the same swiper called in my ajax funtion return the problem.
I tried the make a new one, but previouse one 'stick' to this one and they both works on it
Is there way to detouch one and stick new one, or i should change the code
Beta Was this translation helpful? Give feedback.
All reactions