Piclazyload Implement picture delay loading (including background image) _jquery

Source: Internet
Author: User

The

looks like this:  

/** * Piclazyload picture delay loading, including background image * $ (IMG). Piclazyload ({...})
      * Data-original Pre-loading picture address * Alon/;(function ($) {$.fn.imglazyload = function (settings) {var $this = $ (this),
    _winscrolltop = 0, _winheight = $ (window). Height (); Settings = $.extend ({threshold:0,//Advance height load placeholder: ' Data:image/png;base64,ivborw0kggoaaaansuheugaaaaea aaabcayaaaaffcsjaaaaaxnsr0iars4c6qaaaarnqu1baacxjwv8yquaaaajcehzcwaadsqaaa7eazurdhsaaaansurbvbhxyzh8+pb/ AAFFA0NNPUCLAAAAAELFTKSUQMCC ', Callback:function () {}}, settings| |
    {});
    Execute lazy Load picture lazyloadpic (); Scroll trigger for $ (window). On (' scroll ', function () {_winscrolltop = Document.documentElement.scrollTop | | window.pageyof Fset | |
      Document.body.scrollTop;
    Lazyloadpic ();
    });
        Lazy load Picture function lazyloadpic () {$this. each (function () {var $self = $ (this);
  if ($self. Is (' img ')) {if ($self. attr (' data-original ')) {var _offsettop = $self. Offset ().          if ((_offsettop-settings.threshold) <= (_winheight + _winscrolltop)) {$self. attr (' src ', $self. A
              TTR (' data-original '));
              $self. Removeattr (' data-original ');
              $self. Removeclass (' loadh ');
            Settings.callback ($self); }}else{if ($self. attr (' data-original ')) {//default placeholder picture if ($self. css (' Background-imag
            E ' = = ' None ') {$self. css (' background-image ', ' url (' +settings.placeholder+ ') ');
            var _offsettop = $self. Offset (). Top; if ((_offsettop-settings.threshold) <= (_winheight + _winscrolltop)) {$self. css (' background-image ', ' url (
              ' + $self. attr (' data-original ') + ');
              $self. Removeattr (' data-original ');
            Settings.callback ($self);
    }
          }
        }
      }); }}) (Zepto);

Call

$ (' img '). Imglazyload ({callback:function (data) {
 
 })

The above piclazyload implementation of the picture delay loading (including background picture) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.

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.