0

I want to animate a picture with jQuery. I have this code:

$(document).ready(function(){
$(".label").delay(2000).animate({backgroundPositionX:"0px",backgroundPositionY:"30px"},10000,linear);
$(".label").animate({backgroundPositionX: "-70px" ,backgroundPositionY:"30px"},10000,linear);
$(".label").animate({backgroundPositionX: "-140px" ,backgroundPositionY:"30px"},10000,linear);

but the animation doesn't work. Any idea what is going wrong?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Cheryl
  • 245
  • 1
  • 12

3 Answers3

2

This SO question and answer will help. backgroundPositionX and backgroundPositionY are non standard and won't work in all browsers.

Community
  • 1
  • 1
Stokedout
  • 11,003
  • 5
  • 24
  • 30
  • I have tried with all browsers with no result. I will try to pass only one parameter for background position. Thank you :) – Cheryl Jan 08 '13 at 16:37
1

I edited my code to this:

$(document).ready(function () {
  $(".label").delay(2000).css({
   "backgroundPositionX": "0px",
    "backgroundPositionY": "30px"
  }, 5000, 'linear');
  $(".label").animate({
    "backgroundPositionX": "-70px",
   "backgroundPositionY": "30px"
  }, 5000, 'linear');
  $(".label").animate({
    "backgroundPositionX": "-140px",
    "backgroundPositionY": "30px"
  }, 5000, 'linear');
});

and it works for Chrome.

felipe.zkn
  • 2,012
  • 7
  • 31
  • 63
Cheryl
  • 245
  • 1
  • 12
0
$(document).ready(function () {
  $(".label").delay(2000).animate({
    backgroundPositionX: "0px",
    backgroundPositionY: "30px"
  }, 10000, 'linear');
  $(".label").animate({
   backgroundPositionX: "-70px",
   backgroundPositionY: "30px"
  }, 10000, 'linear');
  $(".label").animate({
    backgroundPositionX: "-140px",
    backgroundPositionY: "30px"
  }, 10000, 'linear');
});

A demo

Anujith
  • 9,370
  • 6
  • 33
  • 48