question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GlideJS destroy() function causes 'resize' event error.

See original GitHub issue

Hi,

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:open
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
SylvainFaurecommented, Mar 26, 2020

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

0reactions
terryjiang2020commented, May 19, 2022

Any plan to fix this? I still have the same issue atm.

Read more comments on GitHub >

github_iconTop 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 >
Bountysource
GlideJS destroy () function causes 'resize' event error.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found