When you're using the responsive option with beforeChange event it will trigger every time you resize your window on the responsive breakpoint value.
You can see this behavior on the link below, you will get a popup whenever you resize your window
Hey @gabskoro, I haven't totally wrapped my head around all the logic, but I know the the checkResponsive method, calls the refresh method which calls changeSlide here. The changeSlide method calls slideHandler, which fire the beforeChange event.
As a work around, I would test to see if there's a resize event before listening for the beforeChange event.
Two ways I see of approaching an enhancement that would attend to this issue. Refactoring the checkResponsive so that it doesn't end up triggering the beforeChange event in slideHandler or passing context information to the change events. Both strike me as being pretty intense augmentations to the logic, since there's so much method separation/dependencies.
Hope that helps!
Tnx for you suggestion, currently found a better solution, check if currentSlide is equal to nextSlide, and if yes don't to anything :)
Good thinking!
@gabskoro How did you write that? Just curious?
I'm having an issue... I'm adding a class to 4 slides, slide-1 through slide-4 - I want to run a function IF the currentSlide is equal to w/e slide it is on. for example if currentSlide equals to slide-2 - run this function, if currentSlide is slide-3 run this function...
Not sure if I should use beforeChange or afterChange.
...
setBeforeSwipe: function() {
var self = this;
carousel.on('beforeChange', function(event, slick, currentSlide, nextSlide) {
if (currentSlide !== nextSlide) {
self.updateGenderQuestions();
}
});
},
...
In your example, it depends on what your function is doing, I needed to prepare the questions before the user sees them and that's why I used the beforeChange event.
Crazily, this had come up before and I'd forgotten. Here's the issue which includes a working fiddle: #1223
Making this the tracking issue and closing the other.
I see beforeChange and afterChange events being triggered for every breakpoint hit (along with breakpoint event). As per my understanding beforeChange and afterChange shouldn't be triggered until the arrow was clicked and only breakpoint event should be triggered on resizing the window.
Is this yet to be fixed or any work around available ?
Most helpful comment
Tnx for you suggestion, currently found a better solution, check if
currentSlideis equal tonextSlide, and if yes don't to anything :)