"jquery plugin" picture preload

Source: Internet
Author: User

The screen scrolls to the current position of the picture to load the picture, setting a Data-url property for the picture that needs to be preloaded.

;(function ($) {/* picture preloaded @author liuming @demo $ (' img[data-url] ').        Imgloading (); */$.fn.            Imgloading=function () {var aimgs =$ (this),/* Cache Picture List */$win = $ (window), Img,imgtop,        Winh = $win. Height (), timmer=null, I, scrolltop; $win. Bind (' Load scroll.            Imgloading ', function () {if (Timmer) {cleartimeout (Timmer);}        Timmer = SetTimeout (eachimg,100);        }); function eachimg () {/* array is empty purge event */if (aimgs.length==0) {return $win. Unbind (' Scroll.            Imgloading ');}            ScrollTop = $win. scrolltop ();                for (i=aimgs.length-1; i>-1; i--) {img = $ (aimgs[i]);                Imgtop = Img.offset (). Top; /* Determine if the picture is on the screen */if (Scrolltop+winh > Imgtop && scrolltop<Imgtop+winh)                    {img.attr (' src ', img.attr (' Data-url '));                Aimgs.splice (i,1); }}}}) (JQuery);

"jquery plugin" picture preload

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.