我在大约一年前将这个代码实现到了几个网站,但最近它还没有起作用。 在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/