slider | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

7th May 2020, 7:23 AM
marunia
marunia - avatar
7 Answers
+ 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.
7th May 2020, 8:01 AM
Kevin ★
+ 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!
7th May 2020, 7:34 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 1
why are you using setInterval() ??
7th May 2020, 7:29 AM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 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?
7th May 2020, 7:34 AM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
0
what i should used?
7th May 2020, 7:32 AM
marunia
marunia - avatar
0
setTimeout?
7th May 2020, 7:32 AM
marunia
marunia - avatar
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
7th May 2020, 7:37 AM
marunia
marunia - avatar