jQuery中的背景位置动画无法在Firefox中使用 [英] Background Position animation in jQuery not working in Firefox

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

问题描述

我正在这里的一个wesbsite上工作: http://www.benjaminpotter.org/portfolio2/

I am working on a wesbsite here: http://www.benjaminpotter.org/portfolio2/

看看加载时的情况,它看起来不错,但是在Firefox中却不是。您知道为什么在jquery中设置动画的背景位置在Firefox中不起作用吗?看看与它关联的脚本animate 此处

Look at the loading splash, it looks all good but not in Firefox. Do you know why background positions being animated in jquery don't work in Firefox? Have a look at the script attached to it called animate here.

推荐答案

dzejkej 所述,背景位置的单独值不是标准的一部分,Firefox也不支持。如 jQuery animate()页面所述:

As noted by dzejkej, separate values for background-position are not part of the standard and not supported by Firefox. As noted on the jQuery animate() page:


所有动画属性均应设置为单个数值

All animated properties should be animated to a single numeric value

这意味着背景位置不符合条件,因为它需要两个值x pos和y pos。

And that means that background-position doesn't qualify, as it requires two values, x pos and y pos.

您将必须使用动画插件。不幸的是,目前jQuery插件站点已关闭,因此我在此处提供了可在Firefox中使用的版本:

You will have to use an animation plugin. Unfortunately, at the moment the jQuery plugins site is down, so I have provided a version that works in Firefox here:

/** jquery.bgpos.js
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
    $.extend($.fx.step,{
        backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
            }
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
    });
})(jQuery);

请参阅此页面以供使用。

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

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