背景jQuery中的位置动画无法在Firefox中运行

在这里一个wesbsite: http://www.benjaminpotter.org/portfolio2/

看看加载启动,它看起来很好,但不是在Firefox中.你知道为什么在jquery中制作动画的背景位置在Firefox中不起作用吗?看看附加到它的脚本叫做animate here.

解决方法

正如dzejkej所指出的,背景位置的单独值不是标准的一部分,并且不受Firefox支持.如 jQuery animate() page所述:

All animated properties should be animated to a single numeric value

这意味着背景位置不合格,因为它需要两个值,x pos和y pos.

您将不得不使用动画插件.不幸的是,目前jQuery插件网站已关闭,所以我在这里提供了一个适用于Firefox的版本:

/** 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],res[4]];
           }
        }
    });
})(jQuery);

请参阅this page获取它的使用参考.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...