GlideJS destroy() function causes 'resize' event error.
See original GitHub issueHi,
So I’m having issues with the destroy functionality. I want the carousel to be initialized on mobile phones, and on resize if the window width is bigger than the JSON init property, destroy the carousel. It looks as follows:
initCarousel() {
if(this.config.init >= this.windowWidth) {
this.carousel = new Glide(this.el, this.config);
this.carousel.on('resize', function() {
this.windowWidth = window.innerWidth;
if(this.config.init < this.windowWidth && this.carousel != undefined) {
this.carousel.destroy();
}
}.bind(this));
this.carousel.mount();
}
}
Here you can see I create the carousel if the init property (640px in this case) is larger or equal to the window width. Then I add a resize event listener which checks if the window is bigger than the init property. If so: destroy.
It destroys it just fine. But as soon as the carousel gets destroyed I get the following error in the console:
Uncaught TypeError: Cannot read property 'resize' of undefined
at EventsBinder.off (glide.esm.js?fe9b:1951)
at Object.unbind (glide.esm.js?fe9b:2006)
at eval (glide.esm.js?fe9b:2015)
at eval (glide.esm.js?fe9b:556)
at Array.forEach (<anonymous>)
at EventsBus.emit (glide.esm.js?fe9b:555)
at Glide$$1.destroy (glide.esm.js?fe9b:699)
at VlCarousel.eval (module.gallery.js?e992:30)
at eval (glide.esm.js?fe9b:556)
at Array.forEach (<anonymous>)
Do I need to unbind this resize event somewhere?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
Top Results From Across the Web
jQuery resize stops functioning, throws error - TypeError
The goal is to disable or enable slider functionality based on browser width. My code works perfectly the first couple times the window...
Read more >Destroy Glide.js - CodePen
URL Extension Required. When linking another Pen as a resource, make sure you use a URL Extension of the type of code you...
Read more >API - Glide.js
destroy(). Usage: Destroy instance and undo all modifications which have been made to the DOM. It also unbinds added event listeners.
Read more >Options - Splide
If true , the carousel makes slides clickable to navigate another ... The timing function for the CSS transition, such as linear ,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, I’m facing the same error and I don’t manage to find any solution Did someone find one or a workaround to this problem? Any help would be appreciated
Any plan to fix this? I still have the same issue atm.