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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:32:42+00:00 2026-05-23T15:32:42+00:00

I am trying to animate the background of an element from it’s current position

  • 0

I am trying to animate the background of an element from it’s current position when the user clicks a button. I am able to do this on the first click but the subsequent clicks fail.

Here’s my code…

var testme;

$(document).ready(function(){     
    $(".navleft").live("click", function() {
        testme = parseInt($(this).css("background-position").replace("% 0%", "").replace("px 0%", ""));
        $(this).parent().animate({backgroundPosition: (testme + 297) + "px"}, 500);
        $(this).parent().find("p").text(testme);
    });
});

EDIT:

$(".navleft").live("click", function() {
    $(this).parent().animate({backgroundPosition: "+=297"}, 500);
});

As suggested below, this works great unless you’re using IE where it resets back to 0 at each click then animates again.

Here’s a link to what I mean… http://jsfiddle.net/TdaSV/

Solution (as a result of being pushed in the right direction):

$(".navleft").live("click", function() {
    $(this).parent().animate({'background-position-x': '+=297'}, 500);
});
  • 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-23T15:32:43+00:00Added an answer on May 23, 2026 at 3:32 pm

    You should first stop the previous animation and then start a new one:

    $(this).parent().stop(true, true).animate({backgroundPosition:...
    

    also if you need to add 297 pixels to the current background position, you don’t need to read the current position, following shoudl work:

    $(this).parent().animate({backgroundPosition: "+=297"}, 500);
    

    see more examples in jquery website.

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

Sidebar

Related Questions

I am trying to animate a div when the user click the button. Each
I have been trying to animate a background position move from a div. The
I'm trying to animate a button's size while constraining its position. It animates to
I'm trying to animate only the y position of a background image. Code works
I'm trying to integrate an animated background with the Fixed Floating Scroll effect from
I'm trying to animate a dot from one point to another on a map.
I'm trying to animate a background image to move down a set amount of
Simple just trying to animate a p-tag #disclaimer to highlight the background color. Example
I'm trying to animate the height of the closest parent of a toggle button:
I'm trying to track the position of an animated element, there are two buttons;

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.