index.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <!DOCTYPE html>
  2. <html class="no-js">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <title>blazy.js - lazyload examples</title>
  7. <meta name="viewport" content="width=device-width, initial-scale=1">
  8. <style> html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}table{border-collapse:collapse;border-spacing:0}
  9. body {
  10. font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
  11. }
  12. h1 {
  13. font-size: 75px;
  14. font-weight: bold;
  15. }
  16. h2 {
  17. font-size:40px;
  18. padding: 20px 0 10px;
  19. }
  20. p{
  21. padding:10px 0;
  22. }
  23. li{
  24. padding: 3px 0;
  25. }
  26. .ratio{
  27. padding-bottom:66.64%;
  28. background-color: #1E1E1E;
  29. height: 0;
  30. width: 100%;
  31. overflow: hidden;
  32. position: relative;
  33. }
  34. .example {
  35. overflow:hidden;
  36. position:relative;
  37. }
  38. .example iframe {
  39. position:absolute;
  40. height:100%;
  41. width:100%;
  42. }
  43. .header {
  44. background: #ececec;
  45. padding: 50px;
  46. color: black;
  47. }
  48. .branding{
  49. max-width: 900px;
  50. margin: 0 auto;
  51. }
  52. .branding pre{
  53. background: #f7f7f7;
  54. color: black;
  55. border-radius: 0;
  56. }
  57. .github {
  58. background: url('http://dinbror.dk/blazy/assets/github.png') 0 0 no-repeat;
  59. height: 149px;
  60. width: 149px;
  61. position: absolute;
  62. top: 0;
  63. right: 0;
  64. }
  65. .section {
  66. margin: 0 auto;
  67. max-width:900px;
  68. }
  69. .container {
  70. background-color: #1E1E1E;
  71. overflow-x: scroll;
  72. overflow-y: hidden;
  73. height:0;
  74. padding-bottom:66%;
  75. }
  76. .list{
  77. font-size:0;
  78. width:300%;
  79. }
  80. .list .wrapper {
  81. display: inline-block;
  82. width:33.3%;
  83. }
  84. img {
  85. max-width: 100%;
  86. }
  87. pre {
  88. background: #212121;
  89. color: white;
  90. padding: 15px 10px 5px;
  91. margin: 0 0 20px;
  92. font-family:Menlo,monospace;
  93. font-size: 14px;
  94. overflow-x: auto;
  95. }
  96. .b-lazy, video{
  97. display:inline-block;
  98. position:absolute;
  99. left:0;
  100. top:0;
  101. height:100%;
  102. width:100%;
  103. }
  104. .list .b-lazy{
  105. max-height:100%;
  106. height:auto;
  107. }
  108. .b-lazy.animate{
  109. opacity:0;
  110. -ms-transform: scale(3);
  111. -moz-transform: scale(3);
  112. -webkit-transform: scale(3);
  113. transform: scale(3);
  114. -ms-transition: all 500ms;
  115. -moz-transition: all 500ms;
  116. -webkit-transition: all 500ms;
  117. transition: all 500ms;
  118. }
  119. .b-loaded.animate {
  120. opacity:1;
  121. -ms-transform: scale(1);
  122. -moz-transform: scale(1);
  123. -webkit-transform: scale(1);
  124. transform: scale(1);
  125. }
  126. @media (max-width: 600px) {
  127. h1 {
  128. font-size: 40px;
  129. }
  130. h2 {
  131. font-size: 25px;
  132. }
  133. }
  134. </style>
  135. </head>
  136. <body>
  137. <div class="header">
  138. <div class="branding">
  139. <h1>blazy.js</h1>
  140. <p>Blazy is a fast, SEO friendly and small but still feature-rich lazy load script. It was originally build for lazy loading images but it can also lazy load any element with a source attribute like iframes, unity games, html5 videos, scripts etc.</p>
  141. <p>Blazy comes with a bunch of features like serving retina images for retina screens, multi-serve images depending on screensize and error handling. <a href="http://dinbror.dk/blog/blazy/?ref=example-page">For a list of all features and more details you can visit the blog post</a>. Blazy works in all modern browsers including IE7+.</p>
  142. <h2>How to lazyload</h2>
  143. <ol>
  144. <li>Add blazy.js to your website</li>
  145. <li>Add the 'b-lazy' class to the elements that should be lazy loaded</li>
  146. <li>Initialize blazy whenever you're ready <br><br>
  147. <pre>
  148. var bLazy = new Blazy({
  149. // Options
  150. });
  151. </pre>
  152. </li>
  153. </ol>
  154. <h2>Examples</h2>
  155. <ol>
  156. <li>Lazy load images</li>
  157. <li>Lazy load background image</li>
  158. <li>Horizontal lazy load</li>
  159. <li>Lazy load iframe</li>
  160. <li>Lazy load HTML5 video</li>
  161. <li>Lazy load script file</li>
  162. </ol>
  163. </div>
  164. <a class="github" href="https://github.com/dinbror/blazy/"></a>
  165. </div>
  166. <div class="section">
  167. <div class="example">
  168. <h2>1.1: Default lazyload image example</h2>
  169. <div class="wrapper ratio">
  170. <img class="b-lazy" src=data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== data-src="http://cdn.dinbror.dk/assets/blazy/01.jpg" alt="Lazy load images example 1a" />
  171. </div>
  172. <pre>
  173. &lt;img class="b-lazy" data-src=&quot;image.jpg&quot; /&gt;
  174. </pre>
  175. </div>
  176. <div class="example">
  177. <h2>1.2: Lazy load image example with css effect</h2>
  178. <div class="wrapper ratio">
  179. <img class="b-lazy animate" src=data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== data-src="http://cdn.dinbror.dk/assets/blazy/02.jpg" alt="Lazy load images example 1b" />
  180. </div>
  181. <pre>
  182. CSS:
  183. .b-lazy {
  184. opacity:0;
  185. transform: scale(3);
  186. transition: all 500ms;
  187. }
  188. .b-loaded {
  189. opacity:1;
  190. transform: scale(1);
  191. }
  192. </pre>
  193. </div>
  194. <div class="example">
  195. <h2>1.3: Lazy load image example with low res image placeholder</h2>
  196. <div class="wrapper ratio">
  197. <img class="b-lazy" src="http://cdn.dinbror.dk/assets/blazy/03-low.jpg" data-src="http://cdn.dinbror.dk/assets/blazy/03.jpg" alt="Lazy load images example 1c" />
  198. </div>
  199. <pre>
  200. &lt;img class="b-lazy" src=&quot;low-res-image.jpg&quot; data-src=&quot;image.jpg&quot; /&gt;
  201. </pre>
  202. </div>
  203. <div class="example">
  204. <h2>1.4: Lazy load image example with srcset</h2>
  205. <div class="wrapper ratio">
  206. <img
  207. alt="Lazy load image example with srcset"
  208. sizes="100vw"
  209. data-srcset="http://placehold.it/1024x682?text=large 1024w,
  210. http://placehold.it/600x400?text=medium 640w,
  211. http://placehold.it/320x214?text=small 320w"
  212. data-src="http://placehold.it/600x400?text=fallback"
  213. class="b-lazy" />
  214. </div>
  215. <pre>
  216. &lt;img class="b-lazy"
  217. sizes=&quot;100vw&quot;
  218. data-srcset=&quot;large.jpg 1024w, medium.jpg 640w, small.jpg 320w&quot;
  219. data-src=&quot;medium.jpg&quot; /&gt;
  220. </pre>
  221. </div>
  222. <div class="example">
  223. <h2>1.5: Lazy load image example with picture element</h2>
  224. <div class="wrapper ratio">
  225. <picture>
  226. <source
  227. media="(min-width: 650px)"
  228. data-srcset="http://placehold.it/1024x682?text=Min-650">
  229. <source
  230. media="(min-width: 465px)"
  231. data-srcset="http://placehold.it/600x400?text=Min-465">
  232. <img
  233. class="b-lazy"
  234. data-src="http://placehold.it/600x400?text=default"
  235. alt="Lazy load image example with picture element">
  236. </picture>
  237. </div>
  238. <pre>
  239. &lt;picture&gt;
  240. &lt;source
  241. media=&quot;(min-width: 650px)&quot;
  242. data-srcset=&quot;image-650.jpg&quot;&gt;
  243. &lt;source
  244. media=&quot;(min-width: 465px)&quot;
  245. data-srcset=&quot;image-465.jpg&quot;&gt;
  246. &lt;img class=&quot;b-lazy&quot;
  247. data-src=&quot;default.jpg&quot;&gt;
  248. &lt;/picture&gt;
  249. </pre>
  250. </div>
  251. <div class="example">
  252. <h2>1.6: Lazyload image with retina support example</h2>
  253. <div class="wrapper ratio">
  254. <img class="b-lazy" src=data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== data-src="http://placehold.it/1024x682?text=Non-Retina|http://placehold.it/1024x682?text=Retina" alt="Lazy load images example 1a" />
  255. </div>
  256. <pre>
  257. &lt;img class="b-lazy" data-src=&quot;image.jpg|retina-image.jpg&quot; /&gt;
  258. </pre>
  259. </div>
  260. <div class="example">
  261. <h2>2: Lazy load background image example</h2>
  262. <div class="wrapper ratio">
  263. <div class="b-lazy" data-src="http://cdn.dinbror.dk/assets/blazy/05.jpg"></div>
  264. </div>
  265. <pre>
  266. &lt;div class="b-lazy" data-src=&quot;image.jpg&quot;&gt;&lt;/div&gt;
  267. </pre>
  268. </div>
  269. <div class="example">
  270. <h2>3: Horizontal lazyload inside container example</h2>
  271. <div class="container">
  272. <ul class="list">
  273. <li class="wrapper ratio">
  274. <img class="b-lazy" src=data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== data-src="http://cdn.dinbror.dk/assets/blazy/04.jpg" alt="Lazy load images example 3 image 1" />
  275. </li>
  276. <li class="wrapper ratio">
  277. <img class="b-lazy" src=data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== data-src="http://cdn.dinbror.dk/assets/blazy/05.jpg" alt="Lazy load images example 3 image 2" />
  278. </li>
  279. <li class="wrapper ratio">
  280. <img class="b-lazy" src=data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== data-src="http://cdn.dinbror.dk/assets/blazy/06.jpg" alt="Lazy load images example 3 image 3" />
  281. </li>
  282. </ul>
  283. </div>
  284. <pre>
  285. var blazy = new Blazy({
  286. container: '.container'
  287. });
  288. </pre>
  289. </div>
  290. <div class="example">
  291. <h2>4: Lazy load iframe example</h2>
  292. <div class="wrapper ratio">
  293. <iframe class="b-lazy" data-src="https://www.youtube.com/embed/uKtjVQ5IJOQ" frameborder="0" allowfullscreen></iframe>
  294. </div>
  295. <pre>
  296. &lt;iframe class=&quot;b-lazy&quot;
  297. data-src=&quot;https://www.youtube.com/embed/uKtjVQ5IJOQ&quot;
  298. frameborder=&quot;0&quot;
  299. allowfullscreen>
  300. &lt;/iframe&gt;
  301. </pre>
  302. </div>
  303. <div class="example">
  304. <h2>5.1: Lazy load HTML5 video example</h2>
  305. <div class="wrapper ratio">
  306. <video class="b-lazy" data-src="http://cdn.dinbror.dk/assets/blazy/SampleVideo_1280x720_1mb.mp4" controls></video>
  307. </div>
  308. <pre>
  309. &lt;video class="b-lazy" data-src=&quot;video.mp4&quot; controls&gt;&lt;/video&gt;
  310. </pre>
  311. </div>
  312. <div class="example">
  313. <h2>5.2: Lazy load HTML5 video advanced example</h2>
  314. <div class="wrapper ratio">
  315. <video class="b-lazy" controls>
  316. <source data-src="http://cdn.dinbror.dk/assets/blazy/big_buck_bunny.mp4" type="video/mp4">
  317. <source data-src="http://cdn.dinbror.dk/assets/blazy/big_buck_bunny.webm" type="video/webm">
  318. Your browser doesn't support HTML5 video tag.
  319. </video>
  320. </div>
  321. <pre>
  322. &lt;video class="b-lazy" controls&gt;
  323. &lt;source data-src=&quot;video.mp4&quot; type=&quot;video/mp4&quot;&gt;
  324. &lt;source data-src=&quot;video.webm&quot; type=&quot;video/webm&quot;&gt;
  325. Your browser doesn&#39;t support HTML5 video tag.
  326. &lt;/video&gt;
  327. </pre>
  328. </div>
  329. <div class="example">
  330. <h2>6: Lazy load script example</h2>
  331. <script class="b-lazy" data-src="script.js" async></script>
  332. <p>Check the console log</p>
  333. <pre>
  334. &lt;script class="b-lazy" data-src=&quot;script.js&quot; async&gt;&lt;/script&gt;
  335. </pre>
  336. </div>
  337. </div>
  338. <script src="../blazy.js"></script>
  339. <script>
  340. window.bLazy = new Blazy({
  341. container: '.container',
  342. success: function(element){
  343. console.log("Element loaded: ", element.nodeName);
  344. }
  345. });
  346. </script>
  347. </body>
  348. </html>