Home > Web Front-end > JS Tutorial > Implementation of jQuery scrolling loading image effect_jquery

Implementation of jQuery scrolling loading image effect_jquery

WBOY
Release: 2016-05-16 17:40:53
Original
1101 people have browsed it

复制代码 代码如下:


/********************Scroll loading image function*****************/
     function scrollLoading(){
         var st = $(window).scrollTop(), sth = 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 < sth) || (posb > st && posb < sth))
             {

                 var url = $temppic.attr("xsrc");
                 if(url != "")
                 {
                    $temppic.attr("src", url);
                    $temppic.attr("xsrc", "");
                 }
             }
         }
     }


 上面是实现滚动加载的一个功能函数;下面在html代码中需要在img中加一个xsrc属性暂时存放真实图片的路径,src中则存放loading图片的路径,为每个需要实现这个功能的图片加一个名字为“scrloadpic”的类。
复制代码 代码如下:



 最后在调用函数。
复制代码 代码如下:

scrollLoading();
$(window).bind("scroll", scrollLoading);
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