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 8912339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:10:25+00:00 2026-06-15T04:10:25+00:00

I am trying to write a function that will move an element by adjusting

  • 0

I am trying to write a function that will move an element by adjusting its ‘left’ style over time. Its currently not working at all in its present form.

    var tab;
    var tabPos;

    function init() {
        tab = document.getElementById("tab");
        tabPos = 10.8;
        tab.style.left = tabPos + '%';
    }

    function moveOver( ) {
        if (tabPos < 15.8)
            {
                setTimeout(function moveOver( ), 100;
                tabPos = tabPos + 0.1;
                tab.style.left = tabPos + '%';
            }
        else if (tabPos > 15.8)
            {
                setTimeout(function moveOver( ), 100;
                tabPos = tabPos - 0.1;
                tab.style.left = tabPos + '%';
            }
     }

The init function successfully sets the initial position of the element but I added the moveOver function to the code the element’s position is no longer set.

  • 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-15T04:10:29+00:00Added an answer on June 15, 2026 at 4:10 am

    Change the lines:

    setTimeout(function moveOver( ), 100;
    

    to

    setTimeout(moveOver, 100);
    

    function moveOver( ) isn’t a valid JavaScript syntax. Also, your brackets (or parenthesis) doesn’t match. Because you have a syntax error, your code will not work.

    For setTimeout, you are supposed to pass a function as the first parameter, so mouseOver or function(){mouseOver();} will work.


    Another problem of your script… is that you will see the element constantly jumping.

    You have two conditions: tabpos < 15.8 and tabpos > 15.8. The condition which execution doesn’t enter either one of both if-blocks is tabpos == 15.8… but JavaScript’s Number is actually a floating point number. Thanks to precision error, 15.8 == 15.7 + 0.1 will result in false, which shows that 15.8 is not exactly the same as 15.7 + 0.1. In fact, 15.7 + 0.1 is approximately equal to 15.799999999999999…

    So I suggest you to use an integer value for tabPos, for example 158, and divide it by 10 only when setting the style.


    A possible result of your code:

    var tab;
    var tabPos;
    
    function init() {
        tab = document.getElementById("tab");
        tabPos = 108;
        tab.style.left = tabPos / 10 + '%';
    }
    
    function moveOver( ) {
        if (tabPos < 158)
            {
                setTimeout(moveOver, 100);
                tabPos = tabPos + 1;
                tab.style.left = tabPos / 10 + '%';
            }
        else if (tabPos > 158)
            {
                setTimeout(moveOver, 100);
                tabPos = tabPos - 1;
                tab.style.left = tabPos / 10 + '%';
            }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a function that will test whether or not a
I'm trying to write a function that will return true or false each time
I am trying to write a JavaScript function that will return its first argument(function)
I am trying to write a function that will allow me to browse for
I'm trying to write a function that will: If there is no region selected,
i am trying to write a function that will make DataRow[column] return nullable typed
I'm trying to write a function that will let me red-shift or blue-shift a
I am trying to write a function that will filter a list of tuples
I am trying to write a function that will: Disable the submit button when
I am trying to write a function that will randomly return an (x,y) co-ordinates

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.