动画背景位置在jQuery 1.4.4上有效,但在1.7.2上无效 [英] Animating background position works on jQuery 1.4.4 but not on 1.7.2

查看:59
本文介绍了动画背景位置在jQuery 1.4.4上有效,但在1.7.2上无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了问题.

我正在修改一个脚本.一切运行良好,但仅在jQuery 1.4.4上运行.当我升级一个版本时,假设最新版本(1.7.2)脚本将无法运行.有什么作用?!

I have a script i'm tinkering with. All runs fine but only on jQuery 1.4.4. When I move up a version, let's say the latest (1.7.2) the script will not run. What gives?!

var bouncespeed = 450;

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);
    });
}

$('.bubble').each(

function() {
    $(this).css({
        backgroundPosition: '5px 5px'
    });
    bounce(this);
});

播放时间!: http://jsfiddle.net/mdecler/rgBeW/2/

推荐答案

这是一个已记录的错误( http://bugs.jquery.com/ticket/8160 )会影响1.5版的jQu​​ery.因此,实际上没有办法在jQuery 1.7.2上对该属性进行动画处理

It's a documented bug (http://bugs.jquery.com/ticket/8160) affecting jQuery from version 1.5. So actually there's no way to animate that property on jQuery 1.7.2

您可以改用.css()代替动画,然后以较小的超时时间调用该函数,但效果并不十分平滑

You could instead use .css() instead of animate and then call the function with a small timeout, but the effect would be not really smooth

否则,改为在div本身上制作动画,更改其margin-top/left properties

Otherwise do instead an animation over the div itself, changing their margin-top/left properties

这篇关于动画背景位置在jQuery 1.4.4上有效,但在1.7.2上无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆