dynamicweb / swiffy-slider

Super fast carousel and slider with touch for optimized websites running in modern browsers.
MIT License
247 stars 30 forks source link

Stop Autoplay on click #63

Closed perdittmann closed 1 year ago

perdittmann commented 1 year ago

Introduces/changes the following functionalities:

  1. Autoplay stops when the user interacts (clicks/taps prev or next buttons or slider indicators) For the case that the design features a pause button shown onhover (to indicate the "pause on hover" functionality), the class "slider-nav-autopause" is removed
  2. Easier way to set the delay with which the indicators react
nicped commented 1 year ago

Thank you for making the time to help improve Swiffy Slider.

I am not sure your changes are the way to go though.

You have added variables outside the swiffyslider instance which could cause a number of issues since the variables would be shared with your own script and other libraries or if you have more than one instance of sliders on the same page - since those variables are not instance dependent. The entire Swiffy slider script is 'stateless' and 'instance-less', so using variables like that would cause issues.

The reason the indicator delay is there is to avoid a huge amount of calls to handleIndicators method. It uses the scroll event listener and if you set the threshold to 0, the code is executed a lot of times causing the browser to use a lot of CPU. You can try to add a console.log inside handleIndicators and see what happens if you set it to 0.

If you really need to control the indicator delay, it should be working the same way as auto play intervals and animation thresholds using attributes - like the data-slider-nav-autoplay-interval attribute - and be read in the initSlider method. This way it will be configurable in markup (as the rest of the Swiffy Slider) and it would be instance specific. But I think it is wrong to have it as it will cause performance problems.

Auto stopping the player on click I can see a use for - also here I would go for a solution using a class like all other configuration - i.e. adding a .slider-nav-autostop option that would stop the player when something is clicked. I can give it a go later on using a class.

perdittmann commented 1 year ago

Thank you for your answer.

The reason for the delay makes total sense to me now, before I suspected a pure design decision. I happily take that part back. :-) Stopping Autoplay on click was the more important part for me (and I'd love a class-based option, that just was beyond my programming skills …).

Thanks a lot! For your support in this, and for this magnificent piece of software as a whole! Per


Per Dittmann | Grafik-Design | Webdesign

Heinsahl 7 · 21244 Buchholz/Nordheide 0176 - 10171516 @.*** https://per.dittmann.hamburg

Nicolai Høeg Pedersen schrieb am 24.10.22 um 10:08:

Thank you for making the time to help improve Swiffy Slider.

I am not sure your changes are the way to go though.

You have added variables outside the swiffyslider instance which could cause a number of issues since the variables would be shared with your own script and other libraries or if you have more than one instance of sliders on the same page - since those variables are not instance dependent. The entire Swiffy slider script is 'stateless' and 'instance-less', so using variables like that would cause issues.

The reason the indicator delay is there is to avoid a huge amount of calls to handleIndicators method. It uses the scroll event listener and if you set the threshold to 0, the code is executed a lot of times causing the browser to use a lot of CPU. You can try to add a console.log inside handleIndicators and see what happens if you set it to 0.

If you really need to control the indicator delay, it should be working the same way as auto play intervals and animation thresholds using attributes - like the data-slider-nav-autoplay-interval attribute - and be read in the initSlider method. This way it will be configurable in markup (as the rest of the Swiffy Slider) and it would be instance specific. But I think it is wrong to have it as it will cause performance problems.

Auto stopping the player on click I can see a use for - also here I would go for a solution using a class like all other configuration - i.e. adding a .slider-nav-autostop option that would stop the player when something is clicked. I can give it a go later on using a class.

— Reply to this email directly, view it on GitHub https://github.com/dynamicweb/swiffy-slider/pull/63#issuecomment-1288595929, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM3UAPYEAUSJ5BY7KDHGCTWEY7XLANCNFSM6AAAAAARMSWVLU. You are receiving this because you authored the thread.Message ID: @.***>