Skip to content Skip to sidebar Skip to footer

Difference Between SetTimeout() And SetInterval()

i am trying to move a small div along a big div in the y-direction according to how much i scrolled down the page.but i've found that using setTimeout() and setInterval() gives tw

Solution 1:

setTimeout executes the function once on a time out. setInterval executes the function repeatedly on and interval

https://developer.mozilla.org/en-US/docs/Web/API/Window.setTimeout
https://developer.mozilla.org/en-US/docs/Web/API/Window.setInterval


Solution 2:

setTimeout will only execute the function once whereas setInterval will execute the function every n seconds (whatever you specify).


Post a Comment for "Difference Between SetTimeout() And SetInterval()"