简体   繁体   English

如何设置页面之间的过渡加载图标?

[英]How to set loading icon for transition between pages?

$(window).load(function() {
    $('#loading').hide();
    $('#container').show();
});

In all my php file, I have above mentioned code for displaying loading icon till the page loads. 在我所有的php文件中,我上面都提到了用于在页面加载之前显示加载图标的代码。 For example : If I execute index.php , loading icon will be shown till index.php gets fully loaded.If it is redirected to example.php when redirecting, no loading icon is displayed, its fully blank. 例如:如果我执行index.php ,将显示加载图标,直到index.php完全加载;如果重定向时将其重定向到example.php ,则不显示任何加载图标,其完全空白。 And if it is redirected fully then loading icon is displayed till that page loads fully. 如果将其完全重定向,则会显示加载图标,直到该页面完全加载为止。

Expected: When redirecting to next page, in that meanwhile too I need loading icon to be displayed . 预期:重定向到下一页时,在此同时,我也需要显示加载图标。

so How to display loading icon between the transition of pages? 那么如何在页面过渡之间显示加载图标?

The trick is to start the loading icon immediately when the page is unloaded. 技巧是在页面卸载后立即启动加载图标。 Then when the new page is loaded, the loading icon must be shown immediately again, only then when the new page is fully loaded the icon can be hidden. 然后,在加载新页面时,必须立即再次显示加载图标,只有在完全加载新页面后,该图标才能隐藏。

// Show the icon immediatly when the script is called.
$('#loading').show();

// show the icon when the page is unloaded
$(window).on('beforeunload', function(event) {
  $('#loading').show();
});

// hide the icon when the page is fully loaded
$(window).on('load', function(event) {
  $('#loading').hide();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM