大约一年前,我在几个网站上实现了这段代码,但最近它一直不起作用。在 Jsfiddle 中,我发现它仍然适用于 jQuery 1.4,但不适用于更高版本。有谁知道jquery升级后是什么破坏了它?
/*---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---*/
或在 jsFiddle:http: //jsfiddle.net/yFKf9/1/