<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [TOC] ## jquery 實例 ``` <img class="js-lazy" data-src="https://img02.sogoucdn.com/app/a/100520146/c0183d183e11944d318ab8b21726fa9d" alt="UTOOLS1596606760927.png" title="UTOOLS1596606760927.png" /> <img class="js-lazy" data-src="https://img01.sogoucdn.com/app/a/100520146/7072191df440036df1ffafe3d62687a3" alt="UTOOLS1596606740452.png" title="UTOOLS1596606740452.png" /> <img class="js-lazy" data-src="https://user-gold-cdn.xitu.io/2020/7/30/1739da4e794a1e0e?w=1199&h=439&f=png&s=34520" alt="UTOOLS1596077698036.png" title="UTOOLS1596077698036.png" /> <img class="js-lazy" data-src="https://user-gold-cdn.xitu.io/2020/7/30/1739da45ac378e00?w=672&h=423&f=png&s=35637" alt="UTOOLS1596077661990.png" title="UTOOLS1596077661990.png" /> <img class="js-lazy" data-src="https://user-gold-cdn.xitu.io/2020/7/30/1739da383454476e?w=1897&h=660&f=png&s=60027" alt="UTOOLS1596077606801.png" title="UTOOLS1596077606801.png" /> <img class="js-lazy" data-src="https://user-gold-cdn.xitu.io/2020/7/30/1739da2cb19210dd?w=1695&h=330&f=png&s=25384" alt="UTOOLS1596077559668.png" title="UTOOLS1596077559668.png" /> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.slim.js"></script> <script type="text/javascript"> $(function () { $(".js-lazy").each(function (i) { var src = $(this).data("src"); $(this).attr("src",src) }) }) </script> ``` ## 原生圖片懶加載 方式一 ``` var bodyScrollHeight = document.body.scrollTop;// body滾動高度 var windowHeight = window.innerHeight;// 視窗高度 var imgs = document.getElementsByClassName('lazyloadimg'); for (var i =0; i < imgs.length; i++) { var imgHeight = imgs[i].offsetTop;// 圖片距離頂部高度 if (imgHeight < windowHeight + bodyScrollHeight) { imgs[i].src = imgs[i].getAttribute('data-src'); img[i].className = img[i].className.replace('lazyloadimg','') } } } ``` 方式二 ``` // <img src="default.png" data-src="https://xxxx/real.png"> function isVisible(el) { const position = el.getBoundingClientRect() const windowHeight = document.documentElement.clientHeight // 頂部邊緣可見 const topVisible = position.top > 0 && position.top < windowHeight; // 底部邊緣可見 const bottomVisible = position.bottom < windowHeight && position.bottom > 0; return topVisible || bottomVisible; } function throttle(func, ms = 1000) { let canRun = true return function (...args) { if (!canRun) return canRun = false setTimeout(() => { func.apply(this, args) canRun = true }, ms) } } function imageLazyLoad() { const images = document.querySelectorAll('img') for (let img of images) { const realSrc = img.dataset.src if (!realSrc) continue if (isVisible(img)) { img.src = realSrc img.dataset.src = '' } } } // 測試 window.addEventListener('load', imageLazyLoad) window.addEventListener('scroll', imageLazyLoad) // or window.addEventListener('scroll', throttle(imageLazyLoad, 1000)) ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看