I often go to Tudou network and find that the function of loading images on the Tudou homepage is very interesting. The thumbnails of all videos on the Tudou homepage from the "Entertainment" section are not loaded after the page is opened, instead, when you drag the scroll bar to the "Entertainment" section, you start to load the image. The advantage of this is, of course, that if a user does not need to view the following content, all the image requests are removed, which is helpful for reducing the server pressure.
I often go to Tudou network and find that the function of loading images on the Tudou homepage is very interesting. The thumbnails of all videos on the Tudou homepage from the "Entertainment" section are not loaded after the page is opened, instead, when you drag the scroll bar to the "Entertainment" section, you start to load the image. The advantage of this is, of course, that if a user does not need to view the following content, all the image requests are removed, which is helpful for reducing the server pressure.
Implementation:
In fact, the implementation principle of Tudou is very simple,
1. First, set the srcof all images with delayed delay to the connection (sprite.gif) of the same small image, and put the connection of the real image into the alt attribute of the image.Code:
<A class = "inner" target = "new" Title = "the heaviest street dance runners and softest street dance runners in history" href = "http://www.tudou.com/programs/view/Utmt1_6Z-lU/">
</A>
2. Bind the window. scroll event, reset the SRC value of all images whose classes are lazyimg in the event, and find the following js on the Tudou homepage:
VaR o = function (){
VaR S = tui. Pos. scrolltop (), q = C;
If (Q. Box [0]) {
VaR r = Q. Box. offset (). Top;
If (R-S> 0 & r-TUI.pos.windowHeight () <s ){
Q. INIT ()
} Else {
Q. Stop ()
}
}
If (! H | S <590) {return true}
Tui. widget. quickplaylist. Load ();
H = false
};
O ();
$ (Window). BIND ("scroll", O );
I have not followed the implementation of The tui. widget. quickplaylist. Load () method. The JS of Tudou is compressed and obfuscated. It looks tired, but you can understand the principle.
Instance:
As mentioned above, it is more practical to come to an instance.
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
Copy the above Code to the local run to see the effect.