Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select event fires multiple times with lazyLoad #504

Closed
fireform opened this issue Dec 19, 2016 · 6 comments
Closed

select event fires multiple times with lazyLoad #504

fireform opened this issue Dec 19, 2016 · 6 comments

Comments

@fireform
Copy link

Hi David!
Thanks a lot for your huge work on this project!

I'm experiencing some odd behavior. So, I run two carousels (main + navigation). If I use "lazyLoad" option in the main carousel, "select" event triggers as many times as how many images specified to lazy load + first image + 1 additional firing (3 in total). I reproduced this on Codepen: http://codepen.io/wpspd/pen/GNzGdg As I understand, this shouldn't happen every time after lazy loading and, moreover, within the navigation. Now I need to use hacks to do not take into account false triggers. Is there any official workaround? Thanks in advance!

@chrisbraddock
Copy link

I just ran in to the same issue. I'm just going to try debouncing it for now.

@danimalweb
Copy link

Same issue here.

@desandro desandro changed the title "Select" event and "asNavFor" + "lazyLoad" problem select event fires multiple times with lazyLoad May 26, 2017
@desandro
Copy link
Member

Thanks for reporting this issue.

For the record, this behavior is how Flickity is supposed to work — currently. When a cell's size changes, Flickity has to re-calculate the position of all the cells. Currently, it triggers select to resolve any position mismatch. I'll admit, it's clunky.

That said, I'm looking into refactoring this behavior. Using select feels like a hack in this case. If you're interested, here's the relevant code

@hirasso
Copy link

hirasso commented Sep 13, 2017

I am having the same issue with select firing many times when using lazyLoad (In my case I defined lazyLoad: 2 and it's firing 5 times). Since I am manipulating the browser history on cell select, it always lags for a very short (but noticeable) time. Of course I can go with the settle event for now, but I would prefer select as it responds immediately.

@marcus-at-localhost
Copy link

I ran into the same problem, using lazyLoad and the settle.flickity event in my case. The event is fired twice and causes weird behaviours in my app.

desandro added a commit that referenced this issue Mar 16, 2018
🔔 add `on` option for capturing initial events
✅ add change test
@desandro
Copy link
Member

🎉 Flickity v2.1.0 has been released with all new change event See docs! 🎉

Triggered when the selected slide is changed.

// jQuery
$carousel.on( 'change.flickity', function( event, index ) {
  console.log( 'Slide changed to ' + index )
});

// vanilla JS
flkty.on( 'change', function( index ) {...});

select will continue to be triggered multiple times, but change is only triggered when the selected slide is changed. Use change to resolve the issue here.

I'm now closing this issue. Please open a new issue if you into trouble with using change. Thanks for sticking with Flickity! 🌈🐻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants