简体   繁体   English

在页面加载之前加载进度条

[英]Load a progress bar before the page loads

I have a basic login page that sends username and password to the database and if the validation is successful, home page is displayed. 我有一个基本的登录页面,该页面将用户名和密码发送到数据库,并且如果验证成功,则显示主页。 The trouble I am facing is that there's a lot of data that is being fetched from the database in this process for displaying the home page. 我面临的问题是,在此过程中,从数据库中获取了大量数据以显示主页。 Hence, the page load takes around 10 seconds. 因此,页面加载大约需要10秒钟。 Is there a way to display a loading progress bar or something for the time that the page loads? 有没有办法在页面加载时显示加载进度栏或其他内容? Currently I am using 目前我正在使用

<script>
    $(window).load(function(){
        $('#dvLoading').fadeOut(4000);
    }); 
</script>

where dvLoading is a simple progress bar gif. 其中dvLoading是一个简单的进度条gif。 This works. 这可行。 However, the problem is that this progress bar displays AFTER the page is loaded. 但是,问题是在加载页面后此进度条显示。 So, this doesn't quite solve the purpose for me. 因此,这并不能完全解决我的目的。 How can I display it as soon as I send the username and password to database? 将用户名和密码发送到数据库后,如何显示它? Any help regarding this would be very helpful. 关于此的任何帮助将非常有帮助。 Thanks for your time. 谢谢你的时间。

Can you try this? 你可以试试这个吗?

<script>
  $(document).ready(function(){
     $('#dvLoading').show();
  });

  $(window).load(function(){
     $('#dvLoading').fadeOut(4000);
  }); 
</script>

Try this: 尝试这个:

// jQuery Plugin and calling function in page load
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(window).load(function() {
$("#pageloaddiv").fadeOut(2000);
});

$('submitbuttonselector').bind('click',function(){
 $("#pageloaddiv").fadeIn(500);//show loading div on submit of username and password
})
</script>

// CSS Class
<style type="text/css">
#pageloaddiv {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 1000;
background: url('http://4.bp.blogspot.com/-hO_3iF0kUXc/Ui_Qa3obNpI/AAAAAAAAFNs/ZP-S8qyUTiY/s1600/pageloader.gif') no-repeat center center;
}
</style>

// loading div to show loading image
<div id="pageloaddiv"></div>

I have a web sockets app that had the same issue so i made a tidy load bar... 我有一个具有相同问题的网络套接字应用程序,所以我做了一个整洁的加载栏...

HTML HTML

<div id="loaderbar"style="position:absolute;top:56px;width:930px;margin-left:auto;margin-right:auto;height:10px;">
    <div id="LOADER"style="background:#E55757;height:10px;width:0px;position:relative;top:0px;left:0px;"max="930"></div>
</div>

Javascript 使用Javascript

var MAXL=0; //MAXL is how many times do you want to see the load bar move to show progress

var LEVENTS=9;

MAXL=parseInt($('#LOADER').attr('max'))/(LEVENTS);

$('#LOADER').animate({width:$('#LOADER').width()+MAXL+'px'}); // drop this line in when ever a stage of progress happens... Should be the same amount of times as LEVENTS

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

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