1

I searched a background animation samples in web. i found this url :

http://jsfiddle.net/rwaldron/TzWQA/

and it works safari and chrome, but the animation background is not working with opera,and Firefox. is there any workaround to make this work across the browsers?

the code it contains is :

$(document).ready(function(){
 $("#puppies")
    .animate({
        backgroundPositionY: "0px",
        backgroundPositionX: "-250px"
    }, 2000);
});
3gwebtrain
  • 14,640
  • 25
  • 121
  • 247
  • 1
    Don't use that, instead, use `backgroundPosition: 'LeftPX TopPX'`and use negative values to transcend where need be. – Ohgodwhy May 24 '12 at 05:48

2 Answers2

1

@AlphaMale 's description of why your code is failing is accurate. I use a handy snippet that makes this work cross browser with the following syntax:

$(document).ready(function(){
  $("#puppies")
    .animate({
        backgroundPosition : "(0 -250px)"
    }, 2000);
});

See it in ACTION! http://jsfiddle.net/dUmNN/1/

Fresheyeball
  • 29,567
  • 20
  • 102
  • 164
1

backgroundPositionY and backgroundPositionX are not supported in FF. So If you want to animate the background you should pass X,Y values collectively to background-position.

Here is a discussion on the same issue:

background-image animation not working in Firefox

Also see:

http://www.protofunc.com/scripts/jquery/backgroundPosition/

http://snook.ca/archives/javascript/jquery-bg-image-animations/

Hope this helps.

Community
  • 1
  • 1
talha2k
  • 24,937
  • 4
  • 62
  • 81