peduarte / wallop

:no_entry: currently unmaintained :no_entry: A minimal JS library for showing & hiding things
1.1k stars 79 forks source link

Problem with restarting autoplay #61

Closed Le-future closed 8 years ago

Le-future commented 8 years ago

Hey mate!

Firstly, thank you so much for this very useful plugin!

I've added an autoplay function and I'm trying to add a restart after the user clicks on his keyboard on the left or right arrow. Problem, if you click more than once on one of the arrow, the slide goes weird ^^

Here is a pen of my work : http://codepen.io/Le-future/pen/Nxexrw

Don't hesitate to press more than twice the arrow of your keyboard to see the problem.

Thanks by advance for any help :-)

peduarte commented 8 years ago

I'm not sure this is an issue with wallop itself, but with the timers in your code and also the CSS.

Im not exactly sure but it seemed like in your CSS you were overriding the animations and stuff.

If you want to write custom animations, you've gotta make sure you really understand how to do it, otherwise it gets tricky. I suggest you use some of the presets.

The real problem though, is that you setTimeout on keydown, meaning every time someone presses left or right, its activating the setTimeout!

I updated your code here with the Fade animation. I also cleaned up your JS a little to use wallop's events rather than faking a click event on an element.

I also think you shouldn't restart the autoplay once the user has interacted with the slider, it's probably not a good user experience.

http://codepen.io/peduarte/pen/pgBPRK?editors=0010

Le-future commented 8 years ago

Thanks for the cleaning about the JS!

Actually you're right, this is not an issue with the plugin. The problem comes from the setTimeout when the user clicks on the arrows. I should stop it before to replay it if the person click more than once.

I try to do that but I can't xD

///////

Thanks for the edit! Yes I'm still hesitating to restart or no the slide...

I'm going to try a solution, I keep the thread posted :-)

peduarte commented 8 years ago

Great, good luck! :+1: