zoukankan      html  css  js  c++  java
  • 图片延迟加载

    <script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
            <script type="text/javascript">
                (function ($) {
                    $.extend($.fn, {
    
                        lazyloadImg: function (option) {
                            var settings = { defObj: null, defHeight: 0 };
                            settings = $.extend(settings, option || {});
                            var defHeight = settings.defHeight,
                            defObj = (typeof settings.defObj == "object") ? settings.defObj.find("img") : $(settings.defObj).find("img");
                            var pageTop = function () {
                                return document.documentElement.clientHeight +
                                Math.max(document.documentElement.scrollTop, document.body.scrollTop) - settings.defHeight;
                            };
                            var imgLoad = function () {
                                defObj.each(function () {
                                    if ($(this).offset().top <= pageTop()) {
                                        var orgSrc = $(this).attr("orgsrc");
                                        if (orgSrc) {
                                            $(this).attr("src", orgSrc).removeAttr("orgsrc");
                                        }
                                    }
                                });
                            };
                            imgLoad();
                            var timer = null;
                            $(window).bind("scroll", function () {
                                if (timer) {
                                    clearTimeout(timer)
                                }
                                timer = setTimeout(function () { imgLoad(); }, 100);
                            });
                        }
    
                    });
                })(jQuery);
                
                
            </script>
            <script type="text/javascript">
                $(function () {
                    $("body").lazyloadImg({ "defObj": "body" });
                });
            </script>
  • 相关阅读:
    将ASCII字符串转换为UNICODE字符串
    GetLastError()返回值大全
    C++构造函数的调用
    DOM – 7.动态创建DOM + 8.innerText innerHTML value
    DOM
    DOM – 4.doucument属性
    用jquery操作xml文件
    請推薦有關網路的書
    Linux命令全称
    轻松架设时时监控工具Cacti
  • 原文地址:https://www.cnblogs.com/daixingqing/p/3047331.html
Copyright © 2011-2022 走看看