熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

JS圖片根據鼠標滾動延時加載的實例代碼

2022-06-13   來源: JSP教程 

  最近研究了京東商城用jQuery的實現如下
就是默認地址賦給img標簽的src屬性顯示時賦給src屬性值

復制代碼 代碼如下:

  
function lazyload(option) {
    var settings = {
defObj: null
defHeight:
    };
    settings = $extend(settings option || {});
    var defHeight = settingsdefHeight;
    var defObj = (typeof settingsdefObj == "object") ? settingsdefObjfind("img") : $(settingsdefObj)find("img");
    var pageTop = function() {
return documentdocumentElementclientHeight + Mathmax(documentdocumentElementscrollTop documentbodyscrollTop) settingsdefHeight;
    };
    var imgLoad = function() {
defObjeach(function() {
    if ($(this)offset()top <= pageTop()) {
        var src = $(this)attr("src");
//已顯示的不用再顯示
if (src) {
                    //顯示後去掉src屬性
    $(this)attr("src" src)removeAttr("src");
}
            }
});
    };
    imgLoad();
    $(window)bind("scroll" function() {
        imgLoad();
    });
}
lazyload({
    defObj:"w"
});


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20483.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.