Swiper init script for mobile issue
Solution 1:
"Your mistake" under else if
you forgot first to Initialize swiper instance
.
This is why when you uncomment this block of code - the page is broken (error: this.swiper.destroy is undefined
).
To destroy an instance you first should create this instance (destroy() is a Method of swiper instance).
const swiper = new Swiper('.swiper-container', {});
swiper.destroy();
Otherwise, your code is like writing:
bla_bla.destroy(); /* Uncaught ReferenceError: bla_bla is not defined */
- Create an instance (Missing in your code)
- Destroy
else if (!mobile_breakpoint.matches){
var init = new Swiper(this, settings) /* missing in your code */
init = this.swiper.destroy();
}
In general - your code is very long ==> next time create a Minimal, Reproducible Example (A lot of code not related to your issue/error).