3
私は約1年前にこのコードをいくつかのウェブサイトに実装しましたが、最近は動作していません。 Jsfiddleでは、jQuery 1.4ではまだ動作しますが、それ以降のバージョンでは動作しないことがわかりました。 jqueryのアップグレード後に何が壊れたのか分かっていますか?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/
バックグラウンド位置の変更を補うプラグインで修正する必要があります。 http://www.protofunc.com/scripts/jquery/backgroundPosition/を試してください。 – j08691