预加载 lazyload

placeholder.png 为占位符小图片
/upload/images/1.png 为数据图片


<img class="lazyload" data-src="/upload/images/1.png" src="/public/images/placeholder.png" alt="">

<div class="img lazyload" data-src="/upload/images/1.png" style="background-image: url('/public/images/placeholder.png');" >div>
<script src="/public/js/lazyload.min.js"></script>
<script>
	// 正常图片
    window.addEventListener("load", function(event) {
        lazyload();
    });
    // 针对背景图
    $(function() {
        $("div.lazyload").lazyload();
        //$("a.lazyload").lazyload();
    });
</script>

你可能感兴趣的:(js,JQ)