Home > Web Front-end > JS Tutorial > JS code to determine page loading status and add mask and buffer animation_javascript skills

JS code to determine page loading status and add mask and buffer animation_javascript skills

WBOY
Release: 2016-05-16 17:49:10
Original
937 people have browsed it
Copy code The code is as follows:

function initialize() {
addcloud(); // is Add a mask to the page
document.onreadystatechange = subSomething; //Listen to the loading status change
}
function addcloud() {
var bodyWidth = document.documentElement.clientWidth;
var bodyHeight = Math .max(document.documentElement.clientHeight, document.body.scrollHeight);
var bgObj = document.createElement("div" );
bgObj.setAttribute( 'id', 'bgDiv' );
bgObj.style.position = "absolute";
bgObj.style.top = "0";
bgObj.style.background = "#000000";
bgObj.style.filter = "progid:DXImageTransform .Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
bgObj.style.opacity = "0.5";
bgObj.style.left = "0";
bgObj.style .width = bodyWidth "px";
bgObj.style.height = bodyHeight "px";
bgObj.style.zIndex = "10000"; //Set its zindex attribute to make this div the largest on the z-axis , there will be no response when the user clicks on anything on the page |
document.body.appendChild(bgObj); //Add mask
var loadingObj = document.createElement("div");
loadingObj.setAttribute ( 'id', 'loadingDiv' );
loadingObj.style.position = "absolute";
loadingObj.style.top = bodyHeight / 2 - 32 "px";
loadingObj.style.left = bodyWidth / 2 "px";
loadingObj.style.background = "url(../img/loading.gif)" ;
loadingObj.style.width = "32px";
loadingObj.style. height = "32px";
loadingObj.style.zIndex = "10000";
document.body.appendChild(loadingObj); //Add loading animation-
}
function removecloud() {
$( "#loadingDiv").remove();
$( "#bgDiv").remove();
}
function subSomething() {
if (document.readyState = = "complete" ) //When the page is loaded, remove the page mask and remove the loading animation -
{
removecloud();
}
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template