Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7728209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:39:39+00:00 2026-06-01T05:39:39+00:00

Does setTimeout work from WITHIN setInterval ? I’m writing some JavaScript to animate some

  • 0

Does setTimeout work from WITHIN setInterval?

I’m writing some JavaScript to animate some DOM elements for a strange artistic project.
The best way for me to explain my question is to give an example:

I have 50 different divs that I need to animate by changing their position on screen, using setInterval. I need each div to be moving at a different rate.

The solution I planned to use was to have a sleep function within my larger changePosition function, so that I could pass a different sleep value for each div. This way, I could assign a unique rate of movement for each div via a dictionary.

The issue that I’m having is that JavaScript does not have “sleep”. It only has setTimeout, which does not seem to be working from within my setInterval loop.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:39:41+00:00Added an answer on June 1, 2026 at 5:39 am

    setTimeout() works perfectly inside of setInterval(), but since you’re trying to emulate sleep() which javascript does not do or have, it sounds to me like you are trying to write synchronous code when setTimeout() works asynchronously. You will need to rethink how you write your code to do this.

    Post some of your code and we can help a lot more specifically.

    I’m not entirely sure I follow what you’re trying to do, but it’s probably easiest to animate N different things each at a different rate by just using a separate timer for each object. Each object’s timer can then be set at it’s own rate and detect it’s own completion and you don’t have to manage them all from some central timer.

    In addition, if you’re writing animation routines from scratch in javascript, you’re doing a lot more work than you need to. This problem has been solved thousands of times already and there’s no reason you have to invent it yourself all over again. A simple Google search for “javascript animation examples” will show all sorts of samples and plenty of code you can base yours off of. Here’s a good tutorial: http://javascript.info/tutorial/animation.

    The popular libraries like jQuery have all sorts of built-in functions for animation that do a lot of the dirty work for you also. Animation can also be done using CSS3 in modern browsers (other than IE).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to work with setTimeout function but that function does not work. First
I am using setTimeout to create animation in Javascript, but it does not seem
I've updated an old javascript of mine to work with Jquery recently. It does
I was curious that what does setTimeout return. So I did a quick test:
Does this pattern: setTimeout(function(){ // do stuff }, 0); Actually return control to the
Why does this call to setTimeout show the alert box but does not do
Does Google force employees who have offers from Facebook to leave immediately?
Does anyone know how to get IntelliSense to work reliably when working in C/C++
I have the below code that does not seem to work at all :(
Possible Duplicate: setTimeout and “this” in JavaScript I am trying to put a timeout

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.