+ 2
slider
how to clear setinterval after clicking button next or prev? setinterval is set on 4 seconds and when you click button after 3 seconds then its not clearing and after 1 second it change slider again. i want to fixed that. https://code.sololearn.com/W8UzXkl89v6E/?ref=app
7 Antworten
+ 2
marunia Use a parameter in order to know if the function was called by the user click or by the setInterval call. If it was called due to user click then clear the interval and set it again.
Check both html and JS.
https://code.sololearn.com/WICyCsE8zPPt/?ref=app
Also it's a bad practice to pass a string as first argument in setInterval because it internally calls eval. Pass the function directly as I did.
+ 3
marunia Hey, you don't at all need to clear the interval. Just check it out :))
https://code.sololearn.com/WfxZhWAIg4kc/?ref=app
The image will update after each 2 seconds!
+ 1
why are you using setInterval() ??
+ 1
marunia i mean the next and prev buttons are working fine, it shows the slides and while clicking those button the slide changes, that's all you want it do, right?
0
what i should used?
0
setTimeout?
0
no i want to do also the timing that after 4 seconds change slide.
but when you click next or prev button there should be also a function that is clearing our time. so when i click the button after 3 seconds, interval should reset and set 4 seconds