瀏覽器加載圖標處於活動狀態時顯示加載圖標

[英]Show loading icon whenever the browser loading icon is active


This might be a stretch, but I'm wondering whether or not it might be possible.

這可能是一個延伸,但我想知道它是否可能。

I'm working on a website that uses PHP for its backend. The problem is, some of the PHP scripts I'm running are quite lengthy, and can translate into page load times that can last a few seconds.

我正在開發一個使用PHP作為其后端的網站。問題是,我正在運行的一些PHP腳本非常冗長,並且可以轉換為可以持續幾秒鍾的頁面加載時間。

Ideally, I would be able to display a loading icon whenever the page is being loaded, but the circumstances differ depending on the page:

理想情況下,我可以在加載頁面時顯示加載圖標,但情況因頁面而異:

  • In some cases, the page is being loaded for the first time,
  • 在某些情況下,頁面是第一次加載,
  • In others, the page is being reloaded after a same-page form submit,
  • 在其他情況下,頁面在同一頁面表單提交后重新加載,
  • Sometimes the form is processed by an off-page script, which then redirects back to the page on which the form is situated (in these cases, since nothing is echoed in the external script the user isn't aware that the script is being processed elsewhere as the page content doesn't change).
  • 有時表單由頁外腳本處理,然后重定向回到表單所在的頁面(在這些情況下,由於在外部腳本中沒有回顯任何內容,因此用戶不知道正在處理腳本其他地方,因為頁面內容不會改變)。

I understand a loading icon could be displayed in each of these cases depending on the trigger, but cannot find a general solution that would display an icon whenever the page is simply loading (regardless of the trigger).

據我所知,根據觸發器的不同,每種情況都可以顯示加載圖標,但無法找到只需加載頁面時顯示圖標的通用解決方案(無論觸發器如何)。

I've noticed that some browsers show a loading icon in the place of the favicon whenever the page is loading (or, at least, Google Chrome does). Is it be possible to know when the browser loading icon is active and display a page loading icon concurrently?

我注意到,無論何時加載頁面(或者至少谷歌Chrome瀏覽器),某些瀏覽器都會在favicon的位置顯示加載圖標。是否可以知道瀏覽器加載圖標何時處於活動狀態並同時顯示頁面加載圖標?

If not, any alternate solution would be much appreciated.

如果沒有,任何替代解決方案將非常感激。

1 个解决方案

#1


0  

Buffering

緩沖

Case your PHP scripts are causing a slow load you must put' em in buffer. So, when the load is finished you can free this buffer.

如果您的PHP腳本導致負載緩慢,則必須將它們放入緩沖區。因此,當加載完成后,您可以釋放此緩沖區。

This isn't so hard to implement.

這並不難實現。

See the PHP output buffering control documentation for this: PHP Output Buffering Control

請參閱PHP輸出緩沖控制文檔:PHP輸出緩沖控制


Finished the loading of the buffer

完成緩沖區的加載

You can make like this: http://jsfiddle.net/S9uR9/

你可以這樣做:http://jsfiddle.net/S9uR9/

    $(window).load(function () {
        //hideLoading();
    });

    hideLoading = function() {
        $('.loading').fadeOut(2000, function() {
            $(".content").fadeIn(1000);        
        });
    };

    hideLoading();

In your page, try to remove the commented line in $(window).load() function and comment the last line hideLoading();.

在你的頁面中,嘗試刪除$(window).load()函數中的注釋行並注釋最后一行hideLoading();.


Detecting browser’s activity

檢測瀏覽器的活動

I've noticed that some browsers show a loading icon in the place of the favicon whenever the page is loading (or, at least, Google Chrome does). Is it be possible to know when the browser loading icon is active and display a page loading icon concurrently?

我注意到,無論何時加載頁面(或者至少谷歌Chrome瀏覽器),某些瀏覽器都會在favicon的位置顯示加載圖標。是否可以知道瀏覽器加載圖標何時處於活動狀態並同時顯示頁面加載圖標?

You can try another alternative. You can detect the network activity. This is more complex to implement, however more interesting, principally if you want a mobile approach.

你可以試試另一種選擇。您可以檢測網絡活動。這實現起來更復雜,但更有趣,主要是如果你想要一個移動方法。

See this article, can help.

看到這篇文章,可以提供幫助。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/09/06/720d339f8dbd3e617ba1489c19a6ba52.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com