0

Hi I have a div with two background like this:

<div class="colCenter" style="height: 750px; top: -25px; width: 72%; left: 18%; background-image: url('img/sfondi/portfolio.jpg'), url('img/sfondi/servizi.jpg');background-position: 0px 0px, 0px -1440px;">
</div> 

if after a click I try to animate it doesn't work why? here is my code:

$(".colCenter").on("click", function() {
    $(".colCenter").animate({
          'backgroundPositionY': '1440px 0px'
    }, 1500, 'linear');
});

In animate I have already tried: 'background-position': '0 1440px, 0 0px' and 'backgroundPositionY': '1440px, 0px'

I'm working in Firefox16 and more than a background in a div is supported

Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171

1 Answers1

1

Why?

http://api.jquery.com/animate/ states that:

All animated properties should be animated to a single numeric value

Multiple backgrounds require multiple numeric values. jQuery doesn't "understand" your requested animation.

Then, how?

search for a jquery plugin that interprets the animation you want to do.

-or-

depending on use case, use CSS3 animations instead of jQuery.

-or-

animate manually with javascript (periodically set background positions, linear interpolation isn't that hard to do)

Roman
  • 5,888
  • 26
  • 47