Home > Web Front-end > JS Tutorial > body text

A faster way than Jquery's document.ready_jquery

WBOY
Release: 2016-05-16 18:28:24
Original
763 people have browsed it

This is an article I saw in the blog park last time. After testing, it is indeed faster than jquery's $(document).ready(function(){....}), and it works well in mainstream browsers such as IE and Firefox. No problem,

I forgot who created it. If the owner sees it, you can contact me and I will add the source of the original text immediately. Please forgive me.

Copy code The code is as follows:

var jb51 =new function() {
dom = [];
dom.isReady = false;
dom.isFunction = function(obj) {
return Object.prototype.toString.call(obj) === "[object Function] ";
}
dom.Ready = function(fn) {
dom.initReady();
//If the DOM tree is not built, go to the second step, store it and kill it together
if (dom.isFunction(fn)) {
if (dom.isReady) {
fn();
//If the DOM has been built, kill one by one
} else {
dom.push(fn);
//Storage loading event
}
}
}
dom.fireReady = function() {
if (dom.isReady) return ;
dom.isReady = true;
for (var i = 0, n = dom.length; i < n; i ) {
var fn = dom[i];
fn( );
}
dom.length = 0;
//Clear event
}
dom.initReady = function() {
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded",
function() {
document.removeEventListener("DOMContentLoaded", arguments.callee, false);
//Clear the loading function
dom.fireReady();
},
false);
} else {
if (document.getElementById) {
document.write("");
document.getElementById("ie-domReady").onreadystatechange = function() {
if (this.readyState === "complete ") {
dom.fireReady();
this.onreadystatechange = null;
this.parentNode.removeChild(this)
}
};
}
}
}
}
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!