We often see the loading prompts that appear when the data is loaded when browsing the web. In fact, this functional principle is very simple, is a div to cover the current page, and then loading on the masking div layer on display, now we come to realize.
1. Current page:
Copy Code code as follows:
<div class= "Current" ><a href= "#" onclick= "showloading ()" >Loading</a></div>
2. Mask layer:
Copy Code code as follows:
<div id= "Over" class= "over" ></div>
3.Loading Display Layer:
Copy Code code as follows:
<div id= "Layout" class= layout "></div>
Overall code:
Copy Code code as follows:
<! DOCTYPE html>
<title></title>
<style type= "Text/css" >
. Current a {
font-size:20px;
}
. OVER {
Display:none;
Position:absolute;
top:0;
left:0;
width:100%;
height:100%;
Background-color: #f5f5f5;
opacity:0.5;
z-index:1000;
}
. layout {
Display:none;
Position:absolute;
top:40%;
left:40%;
width:20%;
height:20%;
z-index:1001;
Text-align:center;
}
</style>
<script type= "Text/javascript" >
function showloading ()
{
document.getElementById ("Over"). Style.display = "block";
document.getElementById ("Layout"). Style.display = "block";
}
</script>
<body>
<div class= "Current" ><a href= "#" onclick= "showloading ()" >Loading</a></div>
<div id= "Over" class= "over" ></div>
<div id= "Layout" class= layout "></div>
</body>
Final effect:
On the internet also see another way to realize, feel good thinking, that is, using JS constantly change the value of HTML tags, to achieve the effect of loading prompts, according to his ideas I realized the next, the code is as follows:
Copy Code code as follows:
<! DOCTYPE html>
<title></title>
<!--<script src= "Scripts/jquery-1.8.2.js" ></script>-->
<style type= "Text/css" >
#tb {
width:100%;
height:100%;
line-height:10px;
}
#tb TR TD {
Text-align:center;
}
. ProgressBar {
font-family:arial;
Font-weight:bolder;
Color:gray;
Background-color:white;
padding:0px;
Border-style:none;
}
. percent {
font-family:arial;
Color:gray;
Text-align:center;
Border-width:medium;
Border-style:none;
}
</style>
<script type= "Text/javascript" >
var bar = 0;
var step = "| |";
/*
* The first type is: $ (document). Ready (function () {...});
*/
$ (function () {
Progress ();
//});
/*
* The second way
*/
Window.onload = function () {
Progress ();
//}
/*
* The third way of simulating $ (document). Ready (function () {...});
*/
(function () {
var ie =!! (Window.attachevent &&!window.opera);
var wk =/webkit\/(\d+)/i.test (navigator.useragent) && (regexp.$1 < 525);
var fn = [];
var run = function () {for (var i = 0; i < fn.length; i++) fn[i] ();
var d = document;
D.ready = function (f) {
if (!ie &&!wk && d.addeventlistener)
Return D.addeventlistener (' domcontentloaded ', F, false);
if (Fn.push (f) > 1) return;
if (IE)
(function () {
try {d.documentelement.doscroll (' left '), run ();}
catch (Err) {settimeout (Arguments.callee, 0);}
})();
else if (wk)
var t = setinterval (function () {
if (/^ (loaded|complete) $/.test (d.readystate))
Clearinterval (t), run ();
}, 0);
};
})();
Document.ready (function () {
Progress ();
});
function Progress () {
Bar = bar + 2;
Step = step + "| |";
document.getElementById ("percent"). Value = bar + "%";
document.getElementById ("ProgressBar"). Value = step;
if (bar <= 98) {
SetTimeout ("Progress ()", 100);
}
}
</script>
<body>
<table id= "TB" >
<tr>
<td>
<input type= "Text" size= "x" class= "percent" id= "percent"/></td>
</tr>
<tr>
<td>
<input type= "Text" size= "x" class= "ProgressBar" id= "ProgressBar"/></td>
</tr>
</table>
</body>
Final effect: