在 Firefox 中请求页面后显示 GIF 动画

发布于 2024-12-07 19:42:36 字数 267 浏览 4 评论 0原文

我有一个简单的 throbber,当 ajax 请求持续超过 3 秒时会自动显示。该 throbber 主要由动画 GIF 图像组成。

现在,我想对常规链接也使用相同的 throbber,这意味着当我单击链接并且服务器需要超过 3 秒的时间来响应时,会显示 throbber。

不幸的是,Firefox 在“重新加载”网页时似乎无法播放动画。 javascript 被调用并使 throbber 正确淡入,但它不旋转。

如何让 Firefox 在加载时播放 GIF 动画?

I have a simple throbber, that is automatically shown when an ajax request lasts longer than 3 seconds. This throbber consists mainly of an animated GIF-Image.

Now, I want to use the same throbber also for regular links, meaning that when I click a link and it takes the server more than 3 seconds to respond, the throbber is shown.

Unfortunately, it seems that firefox is unable to play the animation, while it is "reloading" the webpage. The javascript is called and fades the throbber correctly in, but is it not spinning.

How can I make firefox play the GIF-Animation while it is loading?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨巷深深 2024-12-14 19:42:36

这是函数:

// Throbber manager
function Throbber() { }
Throbber.prototype = {
    image : null,
    requests : 0,

    requestOpened : function(event) {
        if (this.requests == 0) {
            this.image.src = 'throbber.gif';
        }
        this.requests++;
    },

    requestLoaded : function(event) {
        this.requests--;
        if (this.requests == 0) {
            this.image.src = 'throbber_stopped.gif';
        }
    },

    clicked : function() {
        request_manager.abortAll();
    },

    // Called on window load
    attach : function() {
        this.image = document.getElementById('throbber');
        if (this.image && request_manager) {
            request_manager.addEventListener('open', [this, this.requestOpened]);
            request_manager.addEventListener('load', [this, this.requestLoaded]);
            request_manager.addEventListener('abort', [this, this.requestLoaded]);
            this.image.onclick = function() { Throbber.prototype.clicked.apply(throbber, arguments); };
        }
    }
}
var throbber = new Throbber();
window.addEventListener('load', function() { Throbber.prototype.attach.apply(throbber, arguments); }, false);

function SimpleDemo() { }
SimpleDemo.prototype = {
    // The AjaxRequest object
    request : null,

    // Setup and send the request
    run : function() {
        this.request = request_manager.createAjaxRequest();
        this.request.get = {
            one : 1,
            two : 2
        };
        this.request.addEventListener('load', [this, this.ran]);
        this.request.open('GET', 'xml.php');
        var req = requests[this.request.id];
        return setTimeout(function() { req.send(); }, 5000);
    },

    // Triggered when the response returns
    ran : function(event) {
        alert(event.request.xhr.responseText);
    }
}

如果您使用 jQuery:

$("#throbber").show();
/* Your AJAX calls */
$("#throbber").hide();

在调用所有 Ajax 内容之前检查 DOM 何时准备就绪。

使用原型:

document.observe("dom:loaded", function() {
  //your code
});

使用 jQuery:

$(document).ready(function() {
      //your code
});

或参考此:http://plugins.jquery.com/project/throbber

This is the function:

// Throbber manager
function Throbber() { }
Throbber.prototype = {
    image : null,
    requests : 0,

    requestOpened : function(event) {
        if (this.requests == 0) {
            this.image.src = 'throbber.gif';
        }
        this.requests++;
    },

    requestLoaded : function(event) {
        this.requests--;
        if (this.requests == 0) {
            this.image.src = 'throbber_stopped.gif';
        }
    },

    clicked : function() {
        request_manager.abortAll();
    },

    // Called on window load
    attach : function() {
        this.image = document.getElementById('throbber');
        if (this.image && request_manager) {
            request_manager.addEventListener('open', [this, this.requestOpened]);
            request_manager.addEventListener('load', [this, this.requestLoaded]);
            request_manager.addEventListener('abort', [this, this.requestLoaded]);
            this.image.onclick = function() { Throbber.prototype.clicked.apply(throbber, arguments); };
        }
    }
}
var throbber = new Throbber();
window.addEventListener('load', function() { Throbber.prototype.attach.apply(throbber, arguments); }, false);

function SimpleDemo() { }
SimpleDemo.prototype = {
    // The AjaxRequest object
    request : null,

    // Setup and send the request
    run : function() {
        this.request = request_manager.createAjaxRequest();
        this.request.get = {
            one : 1,
            two : 2
        };
        this.request.addEventListener('load', [this, this.ran]);
        this.request.open('GET', 'xml.php');
        var req = requests[this.request.id];
        return setTimeout(function() { req.send(); }, 5000);
    },

    // Triggered when the response returns
    ran : function(event) {
        alert(event.request.xhr.responseText);
    }
}

If you use jQuery:

$("#throbber").show();
/* Your AJAX calls */
$("#throbber").hide();

Check to see when the DOM is ready before calling all your Ajax stuff.

using Prototype:

document.observe("dom:loaded", function() {
  //your code
});

using jQuery:

$(document).ready(function() {
      //your code
});

Or Refer this: http://plugins.jquery.com/project/throbber

最美不过初阳 2024-12-14 19:42:36

我刚刚尝试了我的旧代码,发现这个问题在 Firefox 10.0.2 中不再存在

I just tried my old code and found out that this issue does not exist anymore in Firefox 10.0.2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文