php - how to add a loading gif image to my web page -


how can add loading gif image when every time try load page,i have admin page links on ,i want when click on link before page loads should show gif image,i added javascript code on header tag , in body tag added code

<div id="loading"></div> 

the admin page looks this

<html>     <head>     <script type="text/javascript">         function preloader(){             document.getelementbyid("loading").style.display = "none";             document.getelementbyid("content").style.display = "block";         }//preloader         window.onload = preloader; </script>         <title>profile- admin panel</title>     </head>     <body> <div id="loading"></div>     <?php include 'includes/connect.php'; ?> <?php include 'title_bar.php'; ?> <link rel="stylesheet" href="css/loading.css">  <h3>admin panel system</h3> <p> logged in <b><?php echo $username?></b> [<?php echo $level_name;?>]</p> <?php if($user_level != 1){  header('location : profile.php');  }  ?>  <p>  <ul class="dash">                                       <li>             <a href="#" title="report" class="tip" data-placement="bottom" >             <img src="images/icons/report.png" alt="" />             <span>report</span>             </a>             </li>               <li>             <a href="view.php" title="customers" class="tip" data-placement="bottom" >             <img src="images/icons/customers.png" alt="" />              <span>customers</span>             </a>             </li>             </ul>  </p> <p> <?php if(isset($_get['type']) && !empty($_get['type'])){ ?> <table> <tr><td width='150px'> users</td><td>options</td></tr> <?php  $list_query = mysql_query("select id, username, type users");  while($run_list = mysql_fetch_array($list_query)){   $u_id = $run_list['id'];   $u_username = $run_list['username'];   $u_type = $run_list['type'];  ?>  <tr><td><?php echo $u_username?></td><td>  <?php  if($u_type == 'a'){      echo "<a href='option.php?u_id=$u_id&type=$u_type'>deactivate</a>";  } else{      echo "<a href='option.php?u_id=$u_id&type=$u_type'>activate</a>"; }    ?>   </td></tr>  <?php  } ?> </table>  <?php  } else{     echo "select options above"; }  ?>  </body> </html>  

this have in loading.css

div#content {     display: none;     }  div#loading {                  top: 200 px;     margin: auto;     position: absolute;     z-index: 1000;     width: 160px;     height: 24px;     background: url('../images/loading (1).gif') no-repeat;     cursor: wait;                     } 

you're missing content div. need wrap aside loader in div id "content".

<div id="content"> <h3>admin panel system</h3>     ... </div> </body> 

aside that, on simple page load event fire quickly. unless there lot of images on page user see flicker. if want them see page can add half second delay preload function.

function preloader(){     settimeout(function(){             document.getelementbyid("loading").style.display = "none";         document.getelementbyid("content").style.display = "block";     }, 500); }//preloader 

you can experiment reversing preload (hide content, show loading again) in onunload function when change pages. if pages take while process (slow database calls etc) can flushing page end of loading div before processing happens. http://php.net/manual/en/function.flush.php

ultimately though, i'd suggest loader more trouble it's worth , annoy user. loaders fine ajax when have complete control of request cycle in case i'm not sure. experiment, see works best. luck.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -