简体   繁体   English

在网页加载时向用户显示一条消息

[英]Showing users a message while a web page is loading

I have ported a mobile web app for android. 我已经为Android移植了移动网络应用。 The app is already running very well and it is located here CancerBank . 该应用程序已经运行良好,位于CancerBank上 There are some links that more than 30 seconds to load when a user clicks on them on the android app which can be downloaded here Android App . 有一些链接,当用户点击他们的Android应用程序可以在这里下载了超过30秒加载Android应用程序 Now i want to show the user a message that the page is loading until the page is fully loaded. 现在,我想向用户显示该页面正在加载的消息,直到页面完全加载为止。 Does anyone have a plugin that i can use to accomplish this? 有没有人有我可以用来完成此任务的插件?

My page app is developed in javascript, html5 and css. 我的页面应用程序是用javascript,html5和CSS开发的。

take a look at this. 看看这个。 it seems like a nice plugin. 似乎是一个不错的插件。

http://www.gayadesign.com/scripts/queryLoader2/ http://www.gayadesign.com/scripts/queryLoader2/

If you are using jQuery and the page content is loaded by ajax you can use this: 如果您使用的是jQuery并且页面内容是由ajax加载的,则可以使用以下方法:

$("body").on({
    ajaxStart: function() { 
        // Your code here
    },
    ajaxStop: function() { 
        // your code here 
    }    
});

If you don't use ajax just add a loading div when a user clicks on a link. 如果您不使用ajax,则只需在用户单击链接时添加加载div When the page is loaded and the user gets the new content this div will be gone again because the page was 'refreshed'. 当页面加载并且用户获得新内容时,该div将再次消失,因为页面已“刷新”。 And if you really want to let them wait to all content of the new page is loaded: Add a loading div which displays always, than use javascript to hide it. 如果您真的想让他们等待新页面的所有内容加载,请执行以下操作:添加一个始终显示的加载div ,而不是使用javascript隐藏它。

window.onload = function() {
    // hide your div
}

You could hide all your pages elements by default (eg. <div class='show_this' style='display: none;'>content</div> ) and only show a div containing a "loading" animation. 您可以默认隐藏所有页面元素(例如<div class='show_this' style='display: none;'>content</div> ),仅显示包含“正在加载”动画的div。 Then you'd show the page elements when the page is loaded. 然后,您将在页面加载时显示页面元素。 Eg. 例如。 Put this after you load jQuery: 加载jQuery之后,将其放入:

$(document).ready(function(){
   $('.loading_message').hide();
   $('.show_this').show();
});

Something like that might work. 这样的事情可能会起作用。

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

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