index.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <title>流加载</title>
  2. <!-- 以下样式仅供演示 -->
  3. <style>
  4. #LAY-flow-demo .flow-default{width: 600px; height: 400px; overflow: auto; font-size: 0;}
  5. #LAY-flow-demo .flow-default li{display: inline-block; margin: 0 5px; font-size: 14px; width: 48%; margin-bottom: 10px; height: 100px; line-height: 100px; text-align: center; background-color: #eee;}
  6. #LAY-flow-demo .flow-default img{width: 100%; height: 100%;}
  7. #LAY-flow-demo .site-demo-flow{width: 600px; height: 300px; overflow: auto; text-align: center;}
  8. #LAY-flow-demo .site-demo-flow img{width: 40%; height: 200px; margin: 0 2px 5px 0; border: none;}
  9. @media screen and (max-width: 768px) {
  10. #LAY-flow-demo .flow-default,
  11. #LAY-flow-demo .site-demo-flow{width: 100%;}
  12. #LAY-flow-demo .flow-default li{width: 45%}
  13. #LAY-flow-demo .site-demo-flow img{height: 150px;}
  14. }
  15. </style>
  16. <div class="layui-card layadmin-header">
  17. <div class="layui-breadcrumb" lay-filter="breadcrumb">
  18. <a lay-href="">主页</a>
  19. <a><cite>组件</cite></a>
  20. <a><cite>流加载</cite></a>
  21. </div>
  22. </div>
  23. <div class="layui-fluid" id="LAY-flow-demo">
  24. <div class="layui-row layui-col-space15">
  25. <div class="layui-col-md12">
  26. <div class="layui-card">
  27. <div class="layui-card-header">信息流 - 滚动加载</div>
  28. <div class="layui-card-body">
  29. <ul class="flow-default" id="test-flow-auto"></ul>
  30. </div>
  31. </div>
  32. </div>
  33. <div class="layui-col-md12">
  34. <div class="layui-card">
  35. <div class="layui-card-header">信息流 - 手工加载</div>
  36. <div class="layui-card-body">
  37. <ul class="flow-default" style="height: 300px;" id="test-flow-manual"></ul>
  38. </div>
  39. </div>
  40. </div>
  41. <div class="layui-col-md12">
  42. <div class="layui-card">
  43. <div class="layui-card-header">图片懒加载</div>
  44. <div class="layui-card-body">
  45. <div class="site-demo-flow" id="test-flow-lazyimg">
  46. <img lay-src="https://gw.alicdn.com/bao/uploaded/i2/701696736/TB2PNl5ahQa61Bjy0FhXXaalFXa_!!701696736.jpg_400x400q90.jpg?t=1523290753265">
  47. <img lay-src="https://gw.alicdn.com/bao/uploaded/i2/162734861/TB2V5rsX_gc61BjSZFkXXcTkFXa_!!162734861.jpg_400x400q90.jpg?t=1523290753265">
  48. <img lay-src="https://gw.alicdn.com/bao/uploaded/i4/69476562/TB2htq4XTka61BjSszfXXXN8pXa_!!69476562.jpg_400x400q90.jpg?t=1523290753265">
  49. <img lay-src="https://gw.alicdn.com/bao/uploaded/i1/180558071/TB2sy6jXMQc61BjSZFGXXa1DFXa_!!180558071.jpg_400x400q90.jpg?t=1523290753265">
  50. <img lay-src="https://gw.alicdn.com/bao/uploaded/i2/701696736/TB2PNl5ahQa61Bjy0FhXXaalFXa_!!701696736.jpg_400x400q90.jpg?t=1523290753265">
  51. <img lay-src="https://gw.alicdn.com/bao/uploaded/i3/285892163/TB2qu2HX9Zb61BjSZPfXXaU.pXa_!!285892163.jpg_400x400q90.jpg?t=1523290753265">
  52. <img lay-src="https://gw.alicdn.com/bao/uploaded/i2/704998060/TB2S.gAXTgc61BjSZFkXXcTkFXa_!!704998060.jpg_400x400q90.jpg?t=1523290753265">
  53. <img lay-src="https://gw.alicdn.com/bao/uploaded/i3/117202952/TB25lckX_AX61Bjy0FcXXaSlFXa_!!117202952.jpg_400x400q90.jpg?t=1523290753265">
  54. <img lay-src="https://gw.alicdn.com/bao/uploaded/i2/162734861/TB2qijoX9Zb61BjSZPfXXaU.pXa_!!162734861.jpg_400x400q90.jpg?t=1523290753265">
  55. <img lay-src="https://gw.alicdn.com/bao/uploaded/i3/96216586/TB2S7EfXHMc61BjSZFFXXaDLFXa_!!96216586.jpg_400x400q90.jpg?t=1523290753265">
  56. <img lay-src="https://gw.alicdn.com/bao/uploaded/i8/TB1jSSFNFXXXXcoXFXXYXGcGpXX_M2.SS2_400x400q90.jpg?t=1523290753265">
  57. <img lay-src="https://gw.alicdn.com/bao/uploaded/i2/162734861/TB2ylbsX37c61BjSZFKXXb6hFXa_!!162734861.jpg_400x400q90.jpg?t=1523290753265">
  58. <img lay-src="https://gw.alicdn.com/bao/uploaded/i2/117202952/TB2FdyZajUd61BjSZPcXXc6hXXa_!!117202952.jpg_400x400q90.jpg?t=1523290753265">
  59. <img lay-src="https://gw.alicdn.com/bao/uploaded/i4/777105914/TB2t.qbXZwb61Bjy0FfXXXvlpXa_!!777105914.jpg_400x400q90.jpg?t=1523290753265">
  60. <img lay-src="https://gw.alicdn.com/bao/uploaded/i4/TB1XzupNFXXXXcpXXXXXXXXXXXX_!!0-item_pic.jpg_400x400q90.jpg?t=1523290753265">
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. <script>
  68. layui.use(['admin', 'flow'], function(){
  69. var flow = layui.flow;
  70. flow.load({
  71. elem: '#test-flow-auto' //流加载容器
  72. ,scrollElem: '#test-flow-auto' //滚动条所在元素,一般不用填,此处只是演示需要。
  73. ,done: function(page, next){ //执行下一页的回调
  74. //模拟数据插入
  75. setTimeout(function(){
  76. var lis = [];
  77. for(var i = 0; i < 8; i++){
  78. lis.push('<li>'+ ( (page-1)*8 + i + 1 ) +'</li>')
  79. }
  80. //执行下一页渲染,第二参数为:满足“加载更多”的条件,即后面仍有分页
  81. //pages为Ajax返回的总页数,只有当前页小于总页数的情况下,才会继续出现加载更多
  82. next(lis.join(''), page < 10); //假设总页数为 10
  83. }, 500);
  84. }
  85. });
  86. flow.load({
  87. elem: '#test-flow-manual' //流加载容器
  88. ,scrollElem: '#test-flow-manual' //滚动条所在元素,一般不用填,此处只是演示需要。
  89. ,isAuto: false
  90. ,isLazyimg: true
  91. ,done: function(page, next){ //加载下一页
  92. //模拟插入
  93. setTimeout(function(){
  94. var lis = [];
  95. for(var i = 0; i < 6; i++){
  96. lis.push('<li><img lay-src="http://s17.mogucdn.com/p2/161011/upload_279h87jbc9l0hkl54djjjh42dc7i1_800x480.jpg?v='+ ( (page-1)*6 + i + 1 ) +'"></li>')
  97. }
  98. next(lis.join(''), page < 6); //假设总页数为 6
  99. }, 500);
  100. }
  101. });
  102. //按屏加载图片
  103. flow.lazyimg({
  104. elem: '#test-flow-lazyimg img'
  105. ,scrollElem: '#test-flow-lazyimg' //一般不用设置,此处只是演示需要。
  106. });
  107. });
  108. </script>