Copyright NOTICE: This article is the original article of the blogger, without the permission of the blogger may not be reproduced.
In the writing interaction, the load function makes the onload or the load. Tangled under, under Baidu, under Google ...
The opportunity to organize to avoid forgetting.
and JS window.onload (function) equivalent to the jquery $ (window). onload (function)
One: Window.load this should only indicate the event method, but did not execute, such as hover, click to indicate the event, but it did not execute, must use the hover, onclick he will execute
There is usually a loading effect when the page loads the rendering, and you can use it:
Js:
$ (window). Load (function () {
$ (". Loadingicon"). AddClass ("Loader-chanage");
$ (". Loadingicon"). Fadeout (300,function () {
$ (". Loadingicon"). Remove ();
$ (". Maker"). Show (). Animate ({"Right": "0"},500);
})
$ (window). Load (function) page when the picture and other resources are loaded to complete before execution;
However, this method in Window.onload (function) in JS may be executed completely without loading some resources (such as pictures).
Two: Window.onload this means that after loading all the pages of the page to execute, in the page only allow an onload function, because it can be the number of programmable functions only one:
Js:
<! DOCTYPE html>
Run Result:
Three: Say the above there is also a jquery $ (document). Ready (function), after all the DOM structure in the Web page is finished, it is possible that the contents of the DOM element are not loaded, such as the picture and the relative height width of the set, etc. In this case, you can consider the Load method in jquery, and $ (document). Ready (function) can write functions not limited, such as:
<! DOCTYPE html>
Run Result:
Finally, summarize:
The Js:window.onload page executes the function as soon as it is run, and the picture in the page may not have been loaded yet.
jquery: $ (window). When the picture or something else on the load () page finishes loading, execute the function.
The full format of the call load method is: Load (URL, [data], [callback]) parameter URL address, file type (PHP, HTML, etc.), callback function, also support selector load load ("test.html #内容id名")
Copyright NOTICE: This article is the original article, without the owner's permission to reprint.
View the original ....