Implementation of jQuery Scrolling Image loading effect

Source: Internet
Author: User

Copy codeThe Code is as follows:
<BR> ****************/
Function scrollLoading (){
Var st = $ (window). scrollTop (), something = st + $ (window). height ();
Var $ targetpics = $ ("img. scrloadpic ");
Var len = $ targetpics. length;
For (var I = 0; I <len; I ++)
{
Var $ temppic = $ targetpics. eq (I );
Var post = $ temppic. position (). top;
Var posb = post + $ temppic. height ();

If (post> st & post <TH) | (posb> st & posb <TH ))
{

Var url = $ temppic. attr ("xsrc ");
If (url! = "")
{
$ Temppic. attr ("src", url );
$ Temppic. attr ("xsrc ","");
}
}
}
}


The above is a function that implements rolling loading. In the html code below, you need to add an xsrc attribute in img to temporarily store the path of the real image. In src, the path of the loading image is stored, add a class named "scrloadpic" to each image to implement this function.
Copy codeThe Code is as follows:


Finally, call the function.
Copy codeThe Code is as follows:
ScrollLoading ();
$ (Window). bind ("scroll", scrollLoading );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.