我的编程空间,编程开发者的网络收藏夹
学习永远不晚

js怎么实现无限加载自适应屏幕瀑布流图片效果

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

js怎么实现无限加载自适应屏幕瀑布流图片效果

这篇文章主要讲解了“js怎么实现无限加载自适应屏幕瀑布流图片效果”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“js怎么实现无限加载自适应屏幕瀑布流图片效果”吧!

<!doctype html>

<html>

<head>

         <meta charset="UTF-8">

         <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />

         <title>无限加载自适应屏幕瀑布流图片效果</title>

<meta name="keywords" content="无限加载,自适应,瀑布流,图片效果" />

<meta name="description" content="无限加载自适应屏幕瀑布流图片效果。" />

         <link rel="stylesheet" type="text/css" href="style/base.css">

         <link rel="stylesheet" type="text/css" href="style/index.css">

         <!--[if lt IE 9]>

                   <script class="lazy" data-src="js/css3-mediaqueries.js"></script>

         <![endif]-->

         <script type="text/javascript" class="lazy" data-src="js/jquery-1.8.3.min.js"></script>

         <script type="text/javascript" class="lazy" data-src="js/jQueryColor.js"></script>

         <!--这个插件是瀑布流主插件函数必须-->

         <script type="text/javascript" class="lazy" data-src="js/jquery.masonry.min.js"></script>

         <!--这个插件只是为了扩展jquery的animate函数动态效果可有可无-->

         <script type="text/javascript" class="lazy" data-src="js/jQeasing.js"></script>

         <script type="text/javascript">

        

                   $(function(){

                                    

                                     var container = $('.waterfull ul');

                                     var loading=$('#imloading');

                                     // 初始化loading状态

                                     loading.data("on",true);

                                    

                                     function tores(){

                                               var tmpWid=$(window).width();

                                               if(tmpWid>1280){

                                                        tmpWid=1280;

                                               }else{

                                                        var column=Math.floor(tmpWid/320);

                                                        tmpWid=column*320;

                                               }

                                               $('.waterfull').width(tmpWid);

                                     }

                                     tores();

                                     $(window).resize(function(){

                                               tores();

                                     });

                                     container.imagesLoaded(function(){

                                       container.masonry({

                                            columnWidth: 320,

                                         itemSelector : '.item',

                                         isFitWidth: true,//是否根据浏览器窗口大小自动适应默认false

                                         isAnimated: true,//是否采用jquery动画进行重拍版

                                         isRTL:false,//设置布局的排列方式,即:定位砖块时,是从左向右排列还是从右向左排列。默认值为false,即从左向右

                                         isResizable: true,//是否自动布局默认true

                                         animationOptions: {

                                                        duration: 800,

                                                        easing: 'easeInOutBack',//如果你引用了jQeasing这里就可以添加对应的动态动画效果,如果没引用删除这行,默认是匀速变化

                                                        queue: false//是否队列,从一点填充瀑布流

                                               }

                                       });

                                     });

                                    

                                     var sqlJson=[{'title':'瀑布流其实就是几个函数的事!','intro':'爆料,苏亚雷斯又咬人啦,C罗哪有内马尔帅,梅西今年要不夺冠,你就去泰国吧,老子买了阿根廷赢得彩票,输了就去不成了。','class="lazy" data-src':'images/one.jpg','writer':'标题','date':'2小时前','looked':321},{'title':'瀑布流其实就是几个函数的事!','intro':'爆料了,苏亚雷斯又咬人啦,C罗哪有内马尔帅,梅西今年要不夺冠,你就去泰国吧,老子买了阿根廷赢得彩票,输了就去不成了。','class="lazy" data-src':'images/demo2.jpg','writer':'标题','date':'2小时前','looked':321},{'title':'瀑布流其实就是几个函数的事!','intro':'爆料了,苏亚雷斯又咬人啦,C罗哪有内马尔帅,梅西今年要不夺冠,你就去泰国吧,老子买了阿根廷赢得彩票,输了就去不成了。','class="lazy" data-src':'images/p1.jpg','writer':'标题','date':'2小时前','looked':321},{'title':'瀑布流其实就是几个函数的事!','intro':'爆料了,苏亚雷斯又咬人啦,C罗哪有内马尔帅,梅西今年要不夺冠,你就去泰国吧,老子买了阿根廷赢得彩票,输了就去不成了。','class="lazy" data-src':'images/p1.jpg','writer':'标题','date':'2小时前','looked':321}];

                                    

                                     $(window).scroll(function(){

                                               if(!loading.data("on")) return;

                                               // 计算所有瀑布流块中距离顶部最大,进而在滚动条滚动时,来进行ajax请求,方法很多这里只列举最简单一种,最易理解一种

                                               var itemNum=$('#waterfull').find('.item').length;

                                               var itemArr=[];

                                              itemArr[0]=$('#waterfull').find('.item').eq(itemNum-1).offset().top+$('#waterfull').find('.item').eq(itemNum-1)[0].offsetHeight;

                                              itemArr[1]=$('#waterfull').find('.item').eq(itemNum-2).offset().top+$('#waterfull').find('.item').eq(itemNum-1)[0].offsetHeight;

                                              itemArr[2]=$('#waterfull').find('.item').eq(itemNum-3).offset().top+$('#waterfull').find('.item').eq(itemNum-1)[0].offsetHeight;

                                               var maxTop=Math.max.apply(null,itemArr);

                                               if(maxTop<$(window).height()+$(document).scrollTop()){

                                                        //加载更多数据

                                                        loading.data("on",false).fadeIn(800);

                                                        (function(sqlJson){

                                                                

                                                                 if(itemNum>30){

                                                                           loading.text('就有这么多了!');

                                                                 }else{

                                                                           var html="";

                                                                           for(var i in sqlJson){

                                                                                    html+="<li class='item'><a href='#' class='a-img'><img class="lazy" data-src='"+sqlJson[i].class="lazy" data-src+"'></a>";

                                                                                    html+="<h3 class='li-title'>"+sqlJson[i].title+"</h3>";

                                                                                    html+="<p class='description'>"+sqlJson[i].intro+"</p><div class='qianm clearfloat'>";

                                                                                    html+="<span class='sp1'><b>"+sqlJson[i].looked+"</b>浏览</span>";

                                                                                    html+="<span class='sp2'>"+sqlJson[i].writer+"</span><span class='sp3'>"+sqlJson[i].date+"&nbsp;By</span></div></li>";              

                                                                           }

                                                                          

                                                                           var time=setTimeout(function(){

                                                                                    $(html).find('img').each(function(index){

                                                                                             loadImage($(this).attr('class="lazy" data-src'));

                                                                                    })

                                                                                    var $newElems = $(html).css({ opacity: 0}).appendTo(container);

                                                                                    $newElems.imagesLoaded(function(){

                                                                                             $newElems.animate({ opacity: 1},800);

                                                                                             container.masonry( 'appended', $newElems,true);

                                                                                             loading.data("on",true).fadeOut();

                                                                                             clearTimeout(time);

                                                                         });

                                                                           },800)

                                                                 }

                                                        })(sqlJson);

                                               }

                                     });

                                     function loadImage(url) {

                                          var img = new Image();

                                          //创建一个Image对象,实现图片的预下载

                                           img.class="lazy" data-src = url;

                                           if (img.complete) {

                                              return img.class="lazy" data-src;

                                           }

                                           img.onload = function () {

                                              return img.class="lazy" data-src;

                                           };

                                      };

                                      loadImage('images/one.jpg');

                                    

                                     var rbgB=['#71D3F5','#F0C179','#F28386','#8BD38B'];

                                     $('#waterfull').on('mouseover','.item',function(){

                                               var random=Math.floor(Math.random() * 4);

                                               $(this).stop(true).animate({'backgroundColor':rbgB[random]},1000);

                                     });

                                     $('#waterfull').on('mouseout','.item',function(){

                                               $(this).stop(true).animate({'backgroundColor':'#fff'},1000);

                                     });

                   })

    </script>

</head>

<body>

         <div class="content">

                   <!-- 瀑布流样式开始 -->

                   <div class="waterfull clearfloat" id="waterfull">

                            <ul>

                                     <li class="item">

                                               <a href="#" class="a-img">

                                                        <img class="lazy" data-src="images/t8.jpg" alt="">

                                                       

                                               </a>

                                               <h3 class="li-title" title="手把手教你用css3来创建loading动画(二)">手把手教你用css3来创建loading动画(二)</h3>

                                               <p class="description">HTML 5以前的标准由于考虑到浏览器安全问题并不允许直接跨域通信并不允许直接跨域通信并不允许直接跨域通信,于...</p>

                                               <div class="qianm clearfloat">

                                                        <span class="sp1"><b>688</b>浏览</span>

                                                        <span class="sp2">标题</span>

                                                        <span class="sp3">2小时前&nbsp;By</span>

                                               </div>

                                     </li>

                                     <li class="item">

                                               <a href="#" class="a-img">

                                                        <img class="lazy" data-src="images/t7.jpg" alt="">

                                                       

                                               </a>

                                               <h3 class="li-title" title="手把手教你用css3来创建loading动画(二)">手把手教你用css3来创建loading动画(二)</h3>

                                               <p class="description">HTML 5以前的标准由于考虑到浏览器安全问题并不允许直接跨域通信并不允许直接跨域通信并不允许直接跨域通信,于...</p>

                                               <div class="qianm clearfloat">

                                                        <span class="sp1"><b>688</b>浏览</span>

                                                        <span class="sp2">标题</span>

                                                        <span class="sp3">2小时前&nbsp;By</span>

                                               </div>

                                     </li>

                                     <li class="item">

                                               <a href="#" class="a-img">

                                                        <img class="lazy" data-src="images/t9.jpg" alt="">

                                                       

                                               </a>

                                               <h3 class="li-title" title="手把手教你用css3来创建loading动画(二)">手把手教你用css3来创建loading动画(二)</h3>

                                               <p class="description">HTML 5以前的标准由于考虑到浏览器安全问题并不允许直接跨域通信并不允许直接跨域通信并不允许直接跨域通信,于...</p>

                                               <div class="qianm clearfloat">

                                                        <span class="sp1"><b>688</b>浏览</span>

                                                        <span class="sp2">标题</span>

                                                        <span class="sp3">2小时前&nbsp;By</span>

                                               </div>

                                     </li>

                                     <li class="item">

                                               <a href="#" class="a-img">

                                                        <img class="lazy" data-src="images/t3.jpg" alt="">

                                                       

                                               </a>

                                               <h3 class="li-title" title="手把手教你用css3来创建loading动画(二)">手把手教你用css3来创建loading动画(二)</h3>

                                               <p class="description">HTML 5以前的标准由于考虑到浏览器安全问题并不允许直接跨域通信并不允许直接跨域通信并不允许直接跨域通信,于...</p>

                                               <div class="qianm clearfloat">

                                                        <span class="sp1"><b>688</b>浏览</span>

                                                        <span class="sp2">标题</span>

                                                        <span class="sp3">2小时前&nbsp;By</span>

                                               </div>

                                     </li>

                                     <li class="item">

                                               <a href="#" class="a-img">

                                                        <img class="lazy" data-src="images/t6.jpg" alt="">

                                                       

                                               </a>

                                               <h3 class="li-title" title="手把手教你用css3来创建loading动画(二)">手把手教你用css3来创建loading动画(二)</h3>

                                               <p class="description">HTML 5以前的标准由于考虑到浏览器安全问题并不允许直接跨域通信并不允许直接跨域通信并不允许直接跨域通信,于...</p>

                                               <div class="qianm clearfloat">

                                                        <span class="sp1"><b>688</b>浏览</span>

                                                        <span class="sp2">标题</span>

                                                        <span class="sp3">2小时前&nbsp;By</span>

                                               </div>

                                     </li>

                                     <li class="item">

                                               <a href="#" class="a-img">

                                                        <img class="lazy" data-src="images/t5.jpg" alt=""> 

                                               </a>

                                               <h3 class="li-title" title="手把手教你用css3来创建loading动画(二)">手把手教你用css3来创建loading动画(二)</h3>

                                              <p class="description">HTML 5以前的标准由于考虑到浏览器安全问题并不允许直接跨域通信并不允许直接跨域通信并不允许直接跨域通信,于...</p>

                                               <div class="qianm clearfloat">

                                                        <span class="sp1"><b>688</b>浏览</span>

                                                        <span class="sp2">标题</span>

                                                        <span class="sp3">2小时前&nbsp;By</span>

                                               </div>

                                     </li>

                                     <li class="item">

                                               <a href="#" class="a-img">

                                                        <img class="lazy" data-src="images/t10.jpg" alt="">

                                                       

                                               </a>

                                               <h3 class="li-title" title="手把手教你用css3来创建loading动画(二)">手把手教你用css3来创建loading动画(二)</h3>

                                               <p class="description">HTML 5以前的标准由于考虑到浏览器安全问题并不允许直接跨域通信并不允许直接跨域通信并不允许直接跨域通信,于...</p>

                                               <div class="qianm clearfloat">

                                                        <span class="sp1"><b>688</b>浏览</span>

                                                        <span class="sp2">标题</span>

                                                        <span class="sp3">2小时前&nbsp;By</span>

                                               </div>

                                     </li>

                                     <li class="item">

                                               <a href="#" class="a-img">

                                                        <img class="lazy" data-src="images/t2.jpg" alt="">

                                                       

                                               </a>

                                               <h3 class="li-title" title="手把手教你用css3来创建loading动画(二)">手把手教你用css3来创建loading动画(二)</h3>

                                               <p class="description">HTML 5以前的标准由于考虑到浏览器安全问题并不允许直接跨域通信并不允许直接跨域通信并不允许直接跨域通信,于...</p>

                                               <div class="qianm clearfloat">

                                                        <span class="sp1"><b>688</b>浏览</span>

                                                        <span class="sp2">标题</span>

                                                        <span class="sp3">2小时前&nbsp;By</span>

                                               </div>

                                     </li>

                <li class="item">

                                               <a href="#" class="a-img">

                                                        <img class="lazy" data-src="images/t8.jpg" alt="">

                                                       

                                               </a>

                                               <h3 class="li-title" title="手把手教你用css3来创建loading动画(二)">手把手教你用css3来创建loading动画(二)</h3>

                                               <p class="description">HTML 5以前的标准由于考虑到浏览器安全问题并不允许直接跨域通信并不允许直接跨域通信并不允许直接跨域通信,于...</p>

                                               <div class="qianm clearfloat">

                                                        <span class="sp1"><b>688</b>浏览</span>

                                                        <span class="sp2">标题</span>

                                                        <span class="sp3">2小时前&nbsp;By</span>

                                               </div>

                                     </li>

                                     <li class="item">

                                               <a href="#" class="a-img">

                                                        <img class="lazy" data-src="images/t7.jpg" alt="">

                                                       

                                               </a>

                                               <h3 class="li-title" title="手把手教你用css3来创建loading动画(二)">手把手教你用css3来创建loading动画(二)</h3>

                                               <p class="description">HTML 5以前的标准由于考虑到浏览器安全问题并不允许直接跨域通信并不允许直接跨域通信并不允许直接跨域通信,于...</p>

                                               <div class="qianm clearfloat">

                                                        <span class="sp1"><b>688</b>浏览</span>

                                                        <span class="sp2">标题</span>

                                                        <span class="sp3">2小时前&nbsp;By</span>

                                               </div>

                                     </li>

                                     <li class="item">

                                               <a href="#" class="a-img">

                                                        <img class="lazy" data-src="images/t9.jpg" alt="">

                                                       

                                               </a>

                                               <h3 class="li-title" title="手把手教你用css3来创建loading动画(二)">手把手教你用css3来创建loading动画(二)</h3>

                                               <p class="description">HTML 5以前的标准由于考虑到浏览器安全问题并不允许直接跨域通信并不允许直接跨域通信并不允许直接跨域通信,于...</p>

                                               <div class="qianm clearfloat">

                                                        <span class="sp1"><b>688</b>浏览</span>

                                                        <span class="sp2">标题</span>

                                                        <span class="sp3">2小时前&nbsp;By</span>

                                               </div>

                                     </li>

                            </ul>

                   </div>

                   <!-- loading按钮自己通过样式调整 -->

                   <div id="imloading" style="width:150px;height:30px;line-height:30px;font-size:16px;text-align:center;border-radius:3px;opacity:0.7;background:#000;margin:10px auto 30px;color:#fff;display:none">

                   素材加载中.....

                   </div>

         </div>

 

</body>

</html>

感谢各位的阅读,以上就是“js怎么实现无限加载自适应屏幕瀑布流图片效果”的内容了,经过本文的学习后,相信大家对js怎么实现无限加载自适应屏幕瀑布流图片效果这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是编程网,小编将为大家推送更多相关知识点的文章,欢迎关注!

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

js怎么实现无限加载自适应屏幕瀑布流图片效果

下载Word文档到电脑,方便收藏和打印~

下载Word文档

编程热搜

目录