Jquery.lazyload plug-in implementation of image lazy loading and use method

Source: Internet
Author: User

1. Refer to jquery and jquery.lazyload.js to your page

<scriptsrc="jquery-1.11.0.min.js"></script>

< script src = "jquery.lazyload.js?v=1.9.1" ></ script >2. Add style to pictures lazy picture path reference method with Data-original < img class = "lazy" data-original = "img/bmw_m1_hood.jpg" > < img class = "lazy" data-original = "img/bmw_m1_side.jpg" > < img class = "lazy" data-original = "img/viper_1.jpg" > < img class = "lazy" data-original = "img/viper_corner.jpg" > < img class = "lazy" data-original = "img/bmw_m3_gt.jpg" > < img class = "lazy" data-original = "img/corvette_pitstop.jpg" >JS out of the lazyload and set the image display mode <script type= "text/javascript" charset= "utf-8" >    $( function () {        $( "img.lazy" ).lazyload({effect:  "fadeIn" });    }); </script>You can also use the class= "lazy" in the image, and initialize it using: $( "img" ).lazyload({effect:  "fadeIn" });3. If you want to load the image, you can use threshold to set it, the meaning of the example is: in the picture distance from the screen 180px to advance loading $( "img.lazy" ).lazyload({ threshold :180});4. Parameter Settings $( "img.lazy" ).lazyload({    placeholder :  "img/grey.gif" //用图片提前占位      // placeholder,值为某一图片路径.此图片用来占据将要加载的图片的位置,待图片加载时,占位图则会隐藏    effect:  "fadeIn" // 载入使用何种效果      // effect(特效),值有show(直接显示),fadeIn(淡入),slideDown(下拉)等,常用fadeIn    threshold: 200,  // 提前开始加载      // threshold,值为数字,代表页面高度.如设置为200,表示滚动条在离目标位置还有200的高度时就开始加载图片,可以做到不让用户察觉    event:  ‘click‘ ,   // 事件触发时才加载      // event,值有click(点击),mouseover(鼠标划过),sporty(运动的),foobar(…).可以实现鼠标莫过或点击图片才开始加载,后两个值未测试…    container: $( "#container" ),   // 对某容器中的图片实现效果      // container,值为某容器.lazyload默认在拉动浏览器滚动条时生效,这个参数可以让你在拉动某DIV的滚动条时依次加载其中的图片    failurelimit : 10  // 图片排序混乱时       // failurelimit,值为数字.lazyload默认在找到第一张不在可见区域里的图片时则不再继续加载,但当HTML容器混乱的时候可能出现可见区域内图片并没加载出来的情况,failurelimit意在加载N张可见区域外的图片,以避免出现这个问题. });

Jquery.lazyload plug-in implementation of image lazy loading and use method

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.