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

  • SEARCH
  • Home
  • 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 7561217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:06:26+00:00 2026-05-30T13:06:26+00:00

I was going through this tutorial http://www.schillmania.com/content/projects/javascript-animation-1/ and when I institute the code, I

  • 0

I was going through this tutorial http://www.schillmania.com/content/projects/javascript-animation-1/ and when I institute the code, I get my div to move 10px to the right, but only once, what if I wanted to keep clicking the button and have it move an additional 10px every time, or if the setTimeout() was instituted shouldnt it keep calling that function and adding an additional 10px ever 20ms? I know it’s probably an easy solution, so if anyone could help it would be greatly appreciated. (I’m just learning so no insults).

    <div onclick="invis('one')" id="one"></div>
    <button onclick="domove()">hello</button>
    <div onclick="invis('two')"id="two"></div>
    <div onclick="invis('three')"id="three"></div>

<script type="text/javascript">
    function domove()
        {
            $("one").style.left+=10+'px';
            setTimeout(domove,20);
        }
</script>

I have the #one{} css stylings as follows:

width: 100px;
height: 50px;
float: left;
margin-right: 10px;
background-color: blue;
position: relative;
  • 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-05-30T13:06:27+00:00Added an answer on May 30, 2026 at 1:06 pm

    The problem is with this line:

    $("one").style.left+=10+'px';
    

    Does not equate to “increase style.left by 10”. It equates to “Append ’10px’ to syle.left’s current value.

    This means that style.left is being constantly reset to 10px.

    try this:

    <script type="text/javascript">
    //Global variable to increment every function run
    numberOfPixels = 10;
    function domove()
        {
            $("one").style.left=numberOfPixels+'px';
            numberOfPixels += 10;
            setTimeout(domove,20);
        }
    </script>
    

    Edit: Works fine on this JSFiddle

    Opps… forgot to save the latest revision, it works in THIS fiddle.
    http://jsfiddle.net/CDyQr/1/

    Another Edit: User asked in a comment below how to stay out of the global scope. Here is a method using closures:

    http://jsfiddle.net/CDyQr/2/

    For more info on scope and ways to manipulate it, here is a very detailed Stack Overflow answer:

    What is the scope of variables in JavaScript?

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

Sidebar

Related Questions

I'm going through this tutorial: http://tutorials.jumpstartlab.com/projects/jsattend.html In iteration 7, step 3 we get to
I been going through this tutorial http://www.codeproject.com/KB/linq/BulkOperations_LinqToSQL.aspx and them make a SP like this
I'm going through this tutorial from droid draw: http://www.droiddraw.org/tutorial3.html I'm getting this error when
I am going through this WPF tutorial http://blogs.vertigo.com/personal/alanl/Blog/Lists/Posts/Post.aspx?ID=18 and I have a question about
I am going through this tutorial http://www.9lessons.info/2009/04/exactly-twitter-like-follow-and-remove.html on how to implement a twitter-like follow/unfollow
I decided to learn MVC so I am going through this tutorial, http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part2-cs .
tutorial: http://www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by-example/ I am going through the CloudEdit rails/backbone.js tutrorial and got stuck on
I get the following error when going through the WCF tutorial. HTTP could not
I have been going through the tutorials of Spring 3 at http://www.vaannila.com/spring/spring-annotation-controller-1.html But i
I'm going through a Haskell tutorial and am given this piece of code to

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.