3

I implemented this code to several websites about a year ago, but lately it hasn't been working. In Jsfiddle I figured out it still works with jQuery 1.4 but not with later versions. Does anyone know what broke it after jquery upgrades?

/*---Start Bounce---*/
// Bouncer animation (by Leo Xavier)
// BASE SPEED OF BOUNCING. WILL ADD RAINDOM 0-100 TO UNSYNC BOUNCING
var bouncespeed = 450;

// SELECT ALL A'S EXCEPT... RESET BG-POSITION TO AVOID INITIAL POSITION BUG AND CALL BOUNCER
$('.bubble').each(
function() {
    $(this).css({
        backgroundPosition: '5px 5px'
    });
bounce(this);

});

// ACTUAL BOUNCER. CALLBACK OF ANIMATION IS THE BOUNCER ITSELF, TO LOOP ALL NIGHT LONG
function bounce(currentA) {
newx = Math.floor(10 * Math.random());
newy = Math.floor(3 * Math.random());
newspeed = bouncespeed + Math.floor(10 * Math.random());

$(currentA).animate({
    backgroundPosition: newx + 'px ' + newy + 'px'
}, newspeed, 'linear', function() {
    bounce(currentA);
});
}
/*---End Bounce---*/

Or in jsFiddle: http://jsfiddle.net/yFKf9/1/

inTOWN
  • 1,000
  • 1
  • 7
  • 19

1 Answers1

2

Found an answer for your problem in another question. Apparently, the fact that it worked before 1.5 was not by design.

Community
  • 1
  • 1
mgibsonbr
  • 21,755
  • 7
  • 70
  • 112
  • A plugin to compensate for the background position change should fix it. Try http://www.protofunc.com/scripts/jquery/backgroundPosition/ – j08691 Jan 09 '12 at 02:52