lazyload.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width" />
  6. <title>lazyload</title>
  7. <link rel="stylesheet" href="../css/flickity.css" />
  8. <style>
  9. * { box-sizing: border-box; }
  10. .carousel {
  11. border: 1px solid;
  12. margin-bottom: 40px;
  13. }
  14. .carousel__image {
  15. display: block;
  16. margin-right: 20px;
  17. height: 400px;
  18. max-width: 100%;
  19. min-width: 200px;
  20. background: #DDD;
  21. transition: opacity 0.8s;
  22. opacity: 0;
  23. }
  24. .carousel__image.flickity-lazyloaded {
  25. opacity: 1;
  26. }
  27. .carousel__cell {
  28. width: 80%;
  29. height: 400px;
  30. margin-right: 20px;
  31. background: #DDD;
  32. }
  33. .carousel__cell__image {
  34. display: block;
  35. max-width: 100%;
  36. max-height: 400px;
  37. margin: 0 auto;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <h1>lazyload</h1>
  43. <div class="carousel js-flickity" data-flickity-options='{ "lazyLoad": true }'>
  44. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/r8p3Xgq.jpg" />
  45. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/q9zO6tw.jpg" />
  46. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/bwy74ok.jpg" />
  47. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/hODreXI.jpg" />
  48. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/UORFJ3w.jpg" />
  49. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/bAZWoqx.jpg" />
  50. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/PgmEBSB.jpg" />
  51. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/aboaFoB.jpg" />
  52. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/LkmcILl.jpg" />
  53. </div>
  54. <div class="carousel js-flickity"
  55. data-flickity-options='{ "lazyLoad": 1, "wrapAround": true }'>
  56. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/r8p3Xgq.jpg" />
  57. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/q9zO6tw.jpg" />
  58. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/bwy74ok.jpg" />
  59. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/hODreXI.jpg" />
  60. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/UORFJ3w.jpg" />
  61. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/bAZWoqx.jpg" />
  62. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/PgmEBSB.jpg" />
  63. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/aboaFoB.jpg" />
  64. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/LkmcILl.jpg" />
  65. </div>
  66. <div class="carousel js-flickity"
  67. data-flickity-options='{ "lazyLoad": true }'>
  68. <div class="carousel__cell">
  69. <img class="carousel__cell__image" data-flickity-lazyload="http://i.imgur.com/r8p3Xgq.jpg" /></div>
  70. <div class="carousel__cell">
  71. <img class="carousel__cell__image" data-flickity-lazyload="http://i.imgur.com/q9zO6tw.jpg" /></div>
  72. <div class="carousel__cell">
  73. <img class="carousel__cell__image" data-flickity-lazyload="http://i.imgur.com/bwy74ok.jpg" /></div>
  74. <div class="carousel__cell">
  75. <img class="carousel__cell__image" data-flickity-lazyload="http://i.imgur.com/hODreXI.jpg" /></div>
  76. <div class="carousel__cell">
  77. <img class="carousel__cell__image" data-flickity-lazyload="http://i.imgur.com/UORFJ3w.jpg" /></div>
  78. <div class="carousel__cell">
  79. <img class="carousel__cell__image" data-flickity-lazyload="http://i.imgur.com/bAZWoqx.jpg" /></div>
  80. <div class="carousel__cell">
  81. <img class="carousel__cell__image" data-flickity-lazyload="http://i.imgur.com/PgmEBSB.jpg" /></div>
  82. <div class="carousel__cell">
  83. <img class="carousel__cell__image" data-flickity-lazyload="http://i.imgur.com/aboaFoB.jpg" /></div>
  84. <div class="carousel__cell">
  85. <img class="carousel__cell__image" data-flickity-lazyload="http://i.imgur.com/LkmcILl.jpg" /></div>
  86. </div>
  87. <div class="carousel carousel--jq">
  88. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/r8p3Xgq.jpg" />
  89. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/q9zO6tw.jpg" />
  90. <img class="carousel__image" data-flickity-lazyload="foo.jpg" />
  91. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/hODreXI.jpg" />
  92. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/UORFJ3w.jpg" />
  93. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/bAZWoqx.jpg" />
  94. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/PgmEBSB.jpg" />
  95. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/aboaFoB.jpg" />
  96. <img class="carousel__image" data-flickity-lazyload="http://i.imgur.com/LkmcILl.jpg" />
  97. </div>
  98. <h2>srcset</h2>
  99. <div class="carousel" data-flickity='{ "lazyLoad": true }'>
  100. <img class="carousel__image"
  101. data-flickity-lazyload-src="https://picsum.photos/360/270/?image=718"
  102. data-flickity-lazyload-srcset="
  103. https://picsum.photos/720/540/?image=718 720w,
  104. https://picsum.photos/360/270/?image=718 360w"
  105. sizes="(min-width: 1024px) 720px, 360px"
  106. />
  107. <img class="carousel__image"
  108. data-flickity-lazyload-src="https://picsum.photos/360/270/?image=517"
  109. data-flickity-lazyload-srcset="
  110. https://picsum.photos/720/540/?image=517 720w,
  111. https://picsum.photos/360/270/?image=517 360w"
  112. sizes="(min-width: 1024px) 720px, 360px"
  113. />
  114. <img class="carousel__image"
  115. data-flickity-lazyload-src="https://picsum.photos/360/270/?image=696"
  116. data-flickity-lazyload-srcset="
  117. https://picsum.photos/720/540/?image=696 720w,
  118. https://picsum.photos/360/270/?image=696 360w"
  119. sizes="(min-width: 1024px) 720px, 360px"
  120. />
  121. <img class="carousel__image"
  122. data-flickity-lazyload-src="https://picsum.photos/360/270/?image=56"
  123. data-flickity-lazyload-srcset="
  124. https://picsum.photos/720/540/?image=56 720w,
  125. https://picsum.photos/360/270/?image=56 360w"
  126. sizes="(min-width: 1024px) 720px, 360px"
  127. />
  128. <img class="carousel__image"
  129. data-flickity-lazyload-src="https://picsum.photos/360/270/?image=1084"
  130. data-flickity-lazyload-srcset="
  131. https://picsum.photos/720/540/?image=1084 720w,
  132. https://picsum.photos/360/270/?image=1084 360w"
  133. sizes="(min-width: 1024px) 720px, 360px"
  134. />
  135. <img class="carousel__image"
  136. data-flickity-lazyload-src="https://picsum.photos/360/270/?image=1080"
  137. data-flickity-lazyload-srcset="
  138. https://picsum.photos/720/540/?image=1080 720w,
  139. https://picsum.photos/360/270/?image=1080 360w"
  140. sizes="(min-width: 1024px) 720px, 360px"
  141. />
  142. </div>
  143. <div class="carousel" data-flickity='{ "lazyLoad": true }'>
  144. <div class="carousel__cell">
  145. <img class="carousel__cell__image"
  146. data-flickity-lazyload-srcset="
  147. https://picsum.photos/720/540/?image=718 720w,
  148. https://picsum.photos/360/270/?image=718 360w"
  149. sizes="(min-width: 1024px) 720px, 360px" />
  150. </div>
  151. <div class="carousel__cell">
  152. <img class="carousel__cell__image"
  153. data-flickity-lazyload-srcset="
  154. https://picsum.photos/720/540/?image=517 720w,
  155. https://picsum.photos/360/270/?image=517 360w"
  156. sizes="(min-width: 1024px) 720px, 360px" />
  157. </div>
  158. <div class="carousel__cell">
  159. <img class="carousel__cell__image"
  160. data-flickity-lazyload-srcset="
  161. https://picsum.photos/720/540/?image=696 720w,
  162. https://picsum.photos/360/270/?image=696 360w"
  163. sizes="(min-width: 1024px) 720px, 360px" />
  164. </div>
  165. <div class="carousel__cell">
  166. <img class="carousel__cell__image"
  167. data-flickity-lazyload-srcset="
  168. https://picsum.photos/720/540/?image=56 720w,
  169. https://picsum.photos/360/270/?image=56 360w"
  170. sizes="(min-width: 1024px) 720px, 360px" />
  171. </div>
  172. <div class="carousel__cell">
  173. <img class="carousel__cell__image"
  174. data-flickity-lazyload-srcset="
  175. https://picsum.photos/720/540/?image=1084 720w,
  176. https://picsum.photos/360/270/?image=1084 360w"
  177. sizes="(min-width: 1024px) 720px, 360px" />
  178. </div>
  179. <div class="carousel__cell">
  180. <img class="carousel__cell__image"
  181. data-flickity-lazyload-srcset="
  182. https://picsum.photos/720/540/?image=1080 720w,
  183. https://picsum.photos/360/270/?image=1080 360w"
  184. sizes="(min-width: 1024px) 720px, 360px" />
  185. </div>
  186. </div>
  187. <!-- jQuery -->
  188. <script src="../bower_components/jquery/dist/jquery.js"></script>
  189. <script src="../bower_components/jquery-bridget/jquery-bridget.js"></script>
  190. <!-- dependencies -->
  191. <script src="../bower_components/get-size/get-size.js"></script>
  192. <script src="../bower_components/desandro-matches-selector/matches-selector.js"></script>
  193. <script src="../bower_components/ev-emitter/ev-emitter.js"></script>
  194. <script src="../bower_components/unipointer/unipointer.js"></script>
  195. <script src="../bower_components/unidragger/unidragger.js"></script>
  196. <script src="../bower_components/fizzy-ui-utils/utils.js"></script>
  197. <!-- Flickity -->
  198. <script src="../js/cell.js"></script>
  199. <script src="../js/slide.js"></script>
  200. <script src="../js/animate.js"></script>
  201. <script src="../js/flickity.js"></script>
  202. <script src="../js/drag.js"></script>
  203. <script src="../js/prev-next-button.js"></script>
  204. <script src="../js/page-dots.js"></script>
  205. <script src="../js/player.js"></script>
  206. <script src="../js/add-remove-cell.js"></script>
  207. <script src="../js/lazyload.js"></script>
  208. <script>
  209. var $jQCarousel = $('.carousel--jq').flickity({
  210. lazyLoad: true
  211. });
  212. $jQCarousel.on( 'lazyLoad', function( event, cellElem ) {
  213. });
  214. </script>
  215. </body>
  216. </html>