懶加載

1. 如何判斷一個(gè)元素是否出現(xiàn)在窗口可視范圍(瀏覽器的上邊緣和下邊緣之間,肉眼可視)。寫一個(gè)函數(shù) isVisible實(shí)現(xiàn)

function isVisible($node){
    var windowHeight = $(window).height(),//瀏覽器窗口可視區(qū)域的高度
          scrollTop = $(window).scrollTop(),//窗口滾動(dòng)的頂部偏移量,即此時(shí)頁(yè)面的上邊界到可視區(qū)域的上邊界的偏移量,簡(jiǎn)單的可以理解成整個(gè)頁(yè)面滾動(dòng)了多少距離
          offsetTop = $node.offset().top,//元素的絕對(duì)偏移量,指元素的實(shí)際尺寸(即不包括外邊框margin)的上邊界到頁(yè)面頂端的距離.這個(gè)值不隨窗口滾動(dòng)而改變
          nodeHeight = $node.outerHeight();//元素的實(shí)際尺寸,即 height+padding+border,
                                           // $('#dom').outerHeight(true)#dom的實(shí)際尺寸及外邊距,即 height+padding+border+margin
if(windowHeigth+scrollTop>offsetTop && scrollTop<offsetTop+nodeHeight){
     return true;
   }else{
     return false;
   } 
                 //scrollTop< offsetTop+nodeHeight瀏覽器上邊緣
                 //windowHeight+scrollTop>offsetTop瀏覽器下邊緣
}

2.當(dāng)窗口滾動(dòng)時(shí),判斷一個(gè)元素是不是出現(xiàn)在窗口可視范圍。每次出現(xiàn)都在控制臺(tái)打印 true 。用代碼實(shí)現(xiàn)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>懶加載2</title>
    <style>
         body{
            font: 20px/1.5 ;
            background: #FF9279;
            padding: 30px;
            height: 2500px;
        }
        .p1{
            position: absolute;
            top: 1500px;
            left: 40%;
            padding: 50px;
            border: 2px solid #FF0500;
            background: #0096CC;
        }      

    </style>
</head>
<body>
    <p class="p1">hello</P>
    <script src="jquery-3.2.0.min.js"></script>
    <script>
        $(window).on('scroll',function(){
            if(isShow($('.p1'))){
                console.log(true)
            }else{
                console.log(false)
            }
        })
         function isShow($node){
              var windowHeight = $(window).height(),
                  scrollTop    = $(window).scrollTop(),
                  offsetTop    = $node.offset().top,
                  nodeHeight   = $node.outerHeight();
                  if(windowHeight+scrollTop>offsetTop && scrollTop <offsetTop +nodeHeight){
                      return true
                  }else{
                      return false;
                  }
         }
    </script>
</body>
</html>
20170325_150941.gif

3. 當(dāng)窗口滾動(dòng)時(shí),判斷一個(gè)元素是不是出現(xiàn)在窗口可視范圍。在元素第一次出現(xiàn)時(shí)在控制臺(tái)打印 true,以后再次出現(xiàn)不做任何處理。用代碼實(shí)現(xiàn)

<p class="p1">hello</P>
    <script src="jquery-3.2.0.min.js"></script>
    <script>
        var lock = false//設(shè)置一個(gè)鎖
        $(window).on('scroll',function(){
           if(!lock){//在滾動(dòng)時(shí)不會(huì)在執(zhí)行下面函數(shù)
               isShow($('.p1'))
           }
        })
         
         function isShow($node){
              var windowHeight = $(window).height(),
                  scrollTop    = $(window).scrollTop(),
                  offsetTop    = $node.offset().top,
                  nodeHeight   = $node.outerHeight();
                  if(windowHeight+scrollTop>offsetTop && scrollTop <offsetTop +nodeHeight){
                      
                      console.log(true)
                      lock = true;//當(dāng)?shù)谝怀霈F(xiàn)在可是區(qū)時(shí)把鎖設(shè)置true
                      return true

                  }else{
                      return false;
                  }
         }
<body>
    <p class="p1">hello</P>
    <script src="jquery-3.2.0.min.js"></script>
    <script>
        
        $(window).on('scroll',function(){
            isCheck($('.p1'))
        })
         
         function isShow($node){
              var windowHeight = $(window).height(),
                  scrollTop    = $(window).scrollTop(),
                  offsetTop    = $node.offset().top,
                  nodeHeight   = $node.outerHeight();
                  if(windowHeight+scrollTop>offsetTop && scrollTop <offsetTop +nodeHeight){
                      return true

                  }else{
                      return false;
                  }
         }

         function isCheck($node){
             if($node.not('.load').length===1&& isShow($node)){
                 console.log(true)
                 $node.addClass('load')
             }else{
                 return;
             }
         }
    </script>
</body>
20170325_163904.gif

4. 圖片為什么懶加載,懶加載的原理是什么?

  • 為什么懶加載:如果頁(yè)面的圖片過多,打開時(shí)頁(yè)面時(shí)會(huì)同時(shí)發(fā)很多請(qǐng)求去加載圖片,會(huì)阻塞頁(yè)面的加載速度。

  • 原理:把圖片的src放在自定義的屬性上data-src,當(dāng)滾動(dòng)頁(yè)面時(shí)把可視區(qū)的圖片自定義屬性值換成src屬性值。

5.實(shí)現(xiàn)圖片的懶加載

  <script>
        check(); //打開網(wǎng)頁(yè)把在可視區(qū)的img展示出來
        $(window).on('scroll', check)

        function  check(){
            $('.container img').not('.load').each(function(){//遍歷沒有.load的img
                if(isShow($(this))){//如果在可視區(qū)
                    show($(this))//執(zhí)行函數(shù)
                }
            })
        } 



        function show($imgs){
            $imgs.each(function(){//遍歷所有imgs
                var imgUrl = $(this).attr('data-src');//獲取自定義屬性
                $(this).attr('src',imgUrl);//改變自定義的屬性值
                $(this).addClass('load')
            })
        }


        function isShow($node){
            var windowHeight = $(window).height(),
                scrollTop = $(window).scrollTop(),
                offsetTop = $node.offset().top,
                nodeHeight = $node.height();
            if(windowHeight+scrollTop>offsetTop && scrollTop< offsetTop+nodeHeight){//可視區(qū)域
                return true;
            }else{
                return false;
            }     
        }
    </script>
20170325_171127.gif

6.懶加載新聞

    <style>
        html,body,h2,p,ul,li{
            margin:0px;
            padding:0px;
            list-style: none;
        }
        a{
            color:#333;
            text-decoration:none;
        }
        .container{
            width:600px;
            margin:0 auto;
        }
        .item{
            margin-top:20px;
        }
        .item:after{
            content:'';
            display: block;
            clear:both;
        }
        .item .thumb img{
            width:100px;
            height:100px;
        }
        .item .thumb{
            float:left;
        }
        .item h2{
            margin-left:120px;
            font-size:14px;
          
        }
        .item p{
            margin-left:120px;
            font-size:14px;
            margin-top:60px;
            color:#ccc;
        }
        .load-more{
             visibility: hidden;
             margin: 3px;
             height: 3px;
        }
    </style>
</head>
<body>
    <div class="container">
        <ul class="news">
            <!--<li>
                <a>
                    <div>
                        <img src="" alt="">
                    </div>
                    <h2></h2>
                    <p></p>
                </a>
            </li>
          -->
        </ul>
        <p class="load-more">沒有更多了</p>
    </div>
    
    
    <script src="jquery-3.2.0.min.js"></script>

    <script>
        var pageIndex =0;//每次后端給一頁(yè)數(shù)據(jù) 一頁(yè)數(shù)據(jù)加載2個(gè)新聞
        var isOver = false;// 數(shù)據(jù)全部被加載完以后為true;
        var isNewsArrive = true ; //滾動(dòng)時(shí)數(shù)據(jù)是否到了 給個(gè)鎖
        
        getNews();
        $(window).on('scroll',checkNews);

        function checkNews(){
            if(isShow($('.load-more')) && !isOver && isNewsArrive){
                getNews();
            }
        }

        function getNews(){
            isNewsArrive = false;
            
            $.get('/getNews',{page:pageIndex}).done(function(ret){
                isNewsArrive = true //數(shù)據(jù)到了
                if(ret.status === 0){//與后端約定status===0時(shí)數(shù)據(jù)發(fā)送成功
                    pageIndex++;
                    appendHtml(ret.data)//ret.data獲取后端retNews
                    checkNews();//如果.load-more出現(xiàn)在可視區(qū)繼續(xù)獲取

                }else{
                    alert('獲取新聞出錯(cuò)')
                }
                
            }).fail(function(){
                alert('系統(tǒng)異常')
            })
        


    }
        
      

        function appendHtml(news){
            if(news.length === 0){
                isOver = true;
                
                $('.container').append('<p>沒有更多了</p>')
                return ;//數(shù)據(jù)全部加載完后
            }
            var  html ='';//接受到數(shù)據(jù)后拼接html
            $.each(news,function(){
                html +='<li class="item">';
                html +=' <a href="'+this.link+'">';
                html += '<div class="thumb">  ![]('+ this.img +')</div>';
                html +='<h2>'+this.title+'</h2>';
                html +=' <p>'+this.brif+'</P>';
                html +='</a></li>';

            })
            $('.news').append(html);

        }

        function isShow($node){
            var windowHeight = $(window).height(),
                scrollTop = $(window).scrollTop(),
                offsetTop = $node.offset().top,
                nodeHeight = $node.outerHeight(true);
                if(windowHeight+scrollTop>offsetTop && scrollTop< offsetTop+nodeHeight){
                    return true
                }else{
                    return false
                }
        }
      
    </script>
//后端
app.get('/getNews',function(req,res){
     
    
    var news = [
        {
            link:'http://mil.qq.com/mil_index.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289576514_150120/0',
            title:'韓媒:韓國(guó)旅行社停止銷售中國(guó)旅游產(chǎn)品 銷量銳減',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-1'
        },
          {
            link:'http://news.qq.com/l/milite/jqlw/listjunqingliaowang2012.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290217879_150120/0',
            title:'陸克文:特朗普時(shí)期,臺(tái)灣問題不再是中美臺(tái)面上問題',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-2'
        },
          {
            link:'http://news.qq.com/l/milite/milgn/list2010122872223.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290161671_150120/0',
            title:'樂天免稅店銷售額銳減25% 韓國(guó)免稅店開拓東南亞市場(chǎng)',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-3'
        },
          {
            link:'http://news.qq.com/l/milite/zhoubiansaomiao/list2012095132256.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290216074_150120/0',
            title:'朝中社:美國(guó)“反恐戰(zhàn)”是前所未聞的國(guó)家恐怖行為',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-4'
        },
          {
            link:'http://news.qq.com/l/milite/milhqj/list2010122872321.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289499164_150120/0',
            title:'美前防長(zhǎng):對(duì)朝鮮動(dòng)武風(fēng)險(xiǎn)太大,還是談判吧',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-5'
        },
          {
            link:'http://news.qq.com/l/milite/milhqj/list2010122872321.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290217031_150120/0',
            title:'央視揭秘遼寧艦首次遠(yuǎn)航 露臉的仨人啥來頭?',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-6'
        },
          {
            link:'http://news.qq.com/l/milite/junbei/list2012095132410.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289499766_150120/0',
            title:'媒體:留給和平解決朝核問題的時(shí)間或許所剩無多',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-7'
        },
         {
            link:'http://v.qq.com/cover/j/j02y37wjjgnxdel.html?vid=q0016flpc3k',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289332905_150120/0',
            title:'德女防長(zhǎng)回懟特朗普欠軍費(fèi)言論:我們不欠北約的錢',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-8'
        },
         {
            link:'http://news.qq.com/l/milite/gaoqingtuku/listgaoqingtuku2012.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289495870_150120/0',
            title:'俄媒:學(xué)生超越老師 中國(guó)造艦已遙遙領(lǐng)先俄羅斯',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-9'
        },
         {
            link:'http://mil.qq.com/mil_index.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289576514_150120/0',
            title:'韓媒:韓國(guó)旅行社停止銷售中國(guó)旅游產(chǎn)品 銷量銳減',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-1'
        },
          {
            link:'http://news.qq.com/l/milite/jqlw/listjunqingliaowang2012.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290217879_150120/0',
            title:'陸克文:特朗普時(shí)期,臺(tái)灣問題不再是中美臺(tái)面上問題',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-2'
        },
          {
            link:'http://news.qq.com/l/milite/milgn/list2010122872223.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290161671_150120/0',
            title:'樂天免稅店銷售額銳減25% 韓國(guó)免稅店開拓東南亞市場(chǎng)',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-3'
        },
          {
            link:'http://news.qq.com/l/milite/zhoubiansaomiao/list2012095132256.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290216074_150120/0',
            title:'朝中社:美國(guó)“反恐戰(zhàn)”是前所未聞的國(guó)家恐怖行為',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-4'
        },
          {
            link:'http://news.qq.com/l/milite/milhqj/list2010122872321.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289499164_150120/0',
            title:'美前防長(zhǎng):對(duì)朝鮮動(dòng)武風(fēng)險(xiǎn)太大,還是談判吧',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-5'
        },
          {
            link:'http://news.qq.com/l/milite/milhqj/list2010122872321.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290217031_150120/0',
            title:'央視揭秘遼寧艦首次遠(yuǎn)航 露臉的仨人啥來頭?',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-6'
        },
          {
            link:'http://news.qq.com/l/milite/junbei/list2012095132410.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289499766_150120/0',
            title:'媒體:留給和平解決朝核問題的時(shí)間或許所剩無多',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-7'
        },
         {
            link:'http://v.qq.com/cover/j/j02y37wjjgnxdel.html?vid=q0016flpc3k',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289332905_150120/0',
            title:'德女防長(zhǎng)回懟特朗普欠軍費(fèi)言論:我們不欠北約的錢',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-8'
        },
         {
            link:'http://news.qq.com/l/milite/gaoqingtuku/listgaoqingtuku2012.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289495870_150120/0',
            title:'俄媒:學(xué)生超越老師 中國(guó)造艦已遙遙領(lǐng)先俄羅斯',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-9'
        },
         {
            link:'http://mil.qq.com/mil_index.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289576514_150120/0',
            title:'韓媒:韓國(guó)旅行社停止銷售中國(guó)旅游產(chǎn)品 銷量銳減',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-1'
        },
          {
            link:'http://news.qq.com/l/milite/jqlw/listjunqingliaowang2012.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290217879_150120/0',
            title:'陸克文:特朗普時(shí)期,臺(tái)灣問題不再是中美臺(tái)面上問題',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-2'
        },
          {
            link:'http://news.qq.com/l/milite/milgn/list2010122872223.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290161671_150120/0',
            title:'樂天免稅店銷售額銳減25% 韓國(guó)免稅店開拓東南亞市場(chǎng)',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-3'
        },
          {
            link:'http://news.qq.com/l/milite/zhoubiansaomiao/list2012095132256.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290216074_150120/0',
            title:'朝中社:美國(guó)“反恐戰(zhàn)”是前所未聞的國(guó)家恐怖行為',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-4'
        },
          {
            link:'http://news.qq.com/l/milite/milhqj/list2010122872321.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289499164_150120/0',
            title:'美前防長(zhǎng):對(duì)朝鮮動(dòng)武風(fēng)險(xiǎn)太大,還是談判吧',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-5'
        },
          {
            link:'http://news.qq.com/l/milite/milhqj/list2010122872321.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290217031_150120/0',
            title:'央視揭秘遼寧艦首次遠(yuǎn)航 露臉的仨人啥來頭?',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-6'
        },
          {
            link:'http://news.qq.com/l/milite/junbei/list2012095132410.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289499766_150120/0',
            title:'媒體:留給和平解決朝核問題的時(shí)間或許所剩無多',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-7'
        },
         {
            link:'http://v.qq.com/cover/j/j02y37wjjgnxdel.html?vid=q0016flpc3k',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289332905_150120/0',
            title:'德女防長(zhǎng)回懟特朗普欠軍費(fèi)言論:我們不欠北約的錢',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-8'
        },
         {
            link:'http://news.qq.com/l/milite/gaoqingtuku/listgaoqingtuku2012.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289495870_150120/0',
            title:'俄媒:學(xué)生超越老師 中國(guó)造艦已遙遙領(lǐng)先俄羅斯',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-9'
        },
         {
            link:'http://mil.qq.com/mil_index.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289576514_150120/0',
            title:'韓媒:韓國(guó)旅行社停止銷售中國(guó)旅游產(chǎn)品 銷量銳減',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-1'
        },
          {
            link:'http://news.qq.com/l/milite/jqlw/listjunqingliaowang2012.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290217879_150120/0',
            title:'陸克文:特朗普時(shí)期,臺(tái)灣問題不再是中美臺(tái)面上問題',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-2'
        },
          {
            link:'http://news.qq.com/l/milite/milgn/list2010122872223.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290161671_150120/0',
            title:'樂天免稅店銷售額銳減25% 韓國(guó)免稅店開拓東南亞市場(chǎng)',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-3'
        },
          {
            link:'http://news.qq.com/l/milite/zhoubiansaomiao/list2012095132256.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290216074_150120/0',
            title:'朝中社:美國(guó)“反恐戰(zhàn)”是前所未聞的國(guó)家恐怖行為',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-4'
        },
          {
            link:'http://news.qq.com/l/milite/milhqj/list2010122872321.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289499164_150120/0',
            title:'美前防長(zhǎng):對(duì)朝鮮動(dòng)武風(fēng)險(xiǎn)太大,還是談判吧',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-5'
        },
          {
            link:'http://news.qq.com/l/milite/milhqj/list2010122872321.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1290217031_150120/0',
            title:'央視揭秘遼寧艦首次遠(yuǎn)航 露臉的仨人啥來頭?',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-6'
        },
          {
            link:'http://news.qq.com/l/milite/junbei/list2012095132410.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289499766_150120/0',
            title:'媒體:留給和平解決朝核問題的時(shí)間或許所剩無多',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-7'
        },
         {
            link:'http://v.qq.com/cover/j/j02y37wjjgnxdel.html?vid=q0016flpc3k',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289332905_150120/0',
            title:'德女防長(zhǎng)回懟特朗普欠軍費(fèi)言論:我們不欠北約的錢',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-8'
        },
         {
            link:'http://news.qq.com/l/milite/gaoqingtuku/listgaoqingtuku2012.htm',
            img:'http://inews.gtimg.com/newsapp_ls/0/1289495870_150120/0',
            title:'俄媒:學(xué)生超越老師 中國(guó)造艦已遙遙領(lǐng)先俄羅斯',
            brif:'薩德對(duì)韓國(guó)人民生活的影響-9'
        },
       
    
    ]
    var pageIndex = req.query.page;
    var len = 2;
    var retNews = news.slice(pageIndex*len,pageIndex*len+len)//獲取數(shù)據(jù)第一次0 2 /第二次 2  4 /....

    res.send({
        status:0,
        data:retNews
    })
})
20170325_193905.gif

版權(quán)歸饑人谷 楠柒 所有 如有轉(zhuǎn)載請(qǐng)附上地址

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 1、懶加載 1.什么是懶加載? 懶加載也就是延遲加載。當(dāng)訪問一個(gè)頁(yè)面的時(shí)候,先把img元素或是其他元素的背景圖片路...
    xiaolizhenzhen閱讀 70,497評(píng)論 18 160
  • 1、懶加載1.什么是懶加載?懶加載也就是延遲加載。當(dāng)訪問一個(gè)頁(yè)面的時(shí)候,先把img元素或是其他元素的背景圖片路徑替...
    Gaochengxin閱讀 379評(píng)論 1 2
  • 如何判斷一個(gè)元素是否出現(xiàn)在窗口可視范圍(瀏覽器的上邊緣和下邊緣之間,肉眼可視)。寫一個(gè)函數(shù) isVisible實(shí)現(xiàn)...
    _Dot912閱讀 1,686評(píng)論 10 8
  • 問答題47 /72 常見瀏覽器兼容性問題與解決方案? 參考答案 (1)瀏覽器兼容問題一:不同瀏覽器的標(biāo)簽?zāi)J(rèn)的外補(bǔ)...
    _Yfling閱讀 13,786評(píng)論 1 92
  • 什么是懶加載 對(duì)于用戶暫時(shí)不需要的數(shù)據(jù),不在頁(yè)面打開的時(shí)候就去發(fā)送請(qǐng)求,設(shè)置一個(gè)條件,當(dāng)用戶觸發(fā)條件的時(shí)候再去加載...
    劉圣凱閱讀 247評(píng)論 0 0