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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:02:06+00:00 2026-06-15T01:02:06+00:00

i want to make an animation using setInterval. The image has to change its

  • 0

i want to make an animation using setInterval. The image has to change its position from left to right.

HTML:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <title>animacja</title>
    <style type="text/css">
    #obrazek
    {
        position: relative;
        left: 1px;
    }
    </style>
    <script type="text/javascript"  src="animacja.js"></script>

</head>
<body>
    <img src="smile.jpg" id="obrazek" alt="Usmiech" width="100" height="100" />
</body>
</html>

JavaScript:

window.onload = inicjuj;


function inicjuj()
{
    setInterval(function(){animacja();},1000);
}

function animacja()
{
    var obj = document.getElementById("obrazek");
    var wartosc = parseInt(obj.style.left, 10);
    obj.style.left = (wartosc + 10) + "px";
}

Unfortunalety js doesn’t work and i don’t know why. I’ve checked and the animacja function runs however the image isn’t changing its position.

  • 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-15T01:02:07+00:00Added an answer on June 15, 2026 at 1:02 am

    Your problem is that obj.style only contains information about styles that are specified in the style tag, not style specified in other style sheets, like your <style> tag. Thus, obj.style.left is the empty string, and parseInt('') yields NaN.

    Instead, define your left style property in the style property of the <img> tag:

    <img ... style="left:1px;" />
    

    Or, if it’s very important to keep the styles in separate (e.g. to adhere to some design standard), you can use the window.getComputedStyle function to figure out the object’s actual left style value:

    function animacja()
    {
        var obj = document.getElementById("obrazek");
        var wartosc = parseInt(getComputedStyle(obj).left, 10);
        console.log(parseInt(getComputedStyle(obj).left, 10))
        obj.style.left = (wartosc + 10) + "px";
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In android how to make a image grow from one point using animation? I
I want make a bash script which returns the position of an element from
Hi All I want to make some animation using c#.Animation should include water falling
I have did slider using Viewflipper and that is from right to left mean
I want to make the speed of an animation selectable. I've written the following
I want to make a rotating drillbit animation that shows the complete process of
I want to make an application that shows a frame by frame animation when
I want make datetimepicker in my project. Using jquery how it is possible? I
I have style sheet with a class name changebackgroundcolor i want make change in
I've created an animation using script.aculo.us. However, when the animation is finished, I want

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.