3

I've read a bunch of discussions about this, but none of them have solved this for me.

I am using enquire.js to do my viewport conditions and my code is as follows:

var $slider   = $('#home-farms-slider'),

    sliderOptions = {
        items: 1,
        animateOut: 'fadeOut',
        animateIn: 'fadeIn'
    };

enquire.register("screen and (min-width: 1000px)", {
    match : function() {

        $slider.owlCarousel(sliderOptions);

    },
    unmatch : function() {

        $slider.trigger('destroy.owl.carousel');

    }
});

Everything is working as expected except that when destroy is triggered, my console throws this error:

Uncaught TypeError: Cannot read property '_onResize' of null
owl.carousel.min.js?ver=2.0.0:1

e.onThrottledResize
owl.carousel.min.js?ver=2.0.0:1

m.isFunction.e
jquery.js?ver=1.11.1:2

When that happens, the slider will no longer initialize when my condition is matched. I'm not sure what exactly is happening.

Update 9/15:

I came across this issue on GitHub and did the same to my slider:

https://github.com/OwlFonk/OwlCarousel2/issues/460

I am now able to destroy and reinitialize OwlCarousel because the classes and wrapper are gone. However, I am still getting that console error. The error repeats everytime the viewport resizes, so it's not ideal despite my slider behaving correctly. Any help as to why I'm getting that error would be awesome!

cweiske
  • 30,033
  • 14
  • 133
  • 194
Adam Walter
  • 93
  • 1
  • 1
  • 10
  • Just wanted to say thank you as your enquire code example it let me fix somthing I had been trying todo for a while :P – Someone May 28 '19 at 08:13

1 Answers1

0

Try adding the responsive option as false; using your option block:

sliderOptions = {
    items: 1,
    animateOut: 'fadeOut',
    animateIn: 'fadeIn',
    responsive: false
};

For me adding this stopped the ThrottledResize event from firing, I'm guessing Owl has a delayed event that fires after it's destroyed causing the error. And cheers to your link (9/15) helped me out!

Willieche
  • 24
  • 1
  • This is a bug in beta 2 - When updating to beta 3 the issue is fixed - see : https://github.com/smashingboxes/OwlCarousel2/commit/2064682082e5127620b07f5d4d97a8e883e3d440 – Bjarke Brask Rubeksen Nov 30 '15 at 11:33