hey guys , there is this very simple pluggin called unviel.js for lazy loading . i have used it in a few of my projects but i would like to understand it better a bit .
below is an example that actually works .
basically what u do is , just take a gif image and load it in the src attribute and than in another data-src attribute you actually insert the image you actually want to display.
and than you run the pluggin with the following peice of code :
- $( document ).ready( function () {
- $( "img" ).unveil();
- });
below is an example that actually works .
-
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Test</title>
-
- <script src="js/jquery.min.js"></script>
- <script src="js/jquery.unveil.js"></script>
- <script src="js/test.js"></script>
-
-
-
- <style>
- body{
- background:#eee;
- }
- .main{
- width: 800px;
- margin: 0 auto;
- text-align: center;
- }
-
- .main img{
- width: 100%;
- max-width: 700px;
- border: 10px solid #fff;
- box-shadow: 1px 1px 10px rgba(0,0,0,.5);
-
- }
-
- .main figure{
- margin-top: 20%;
- }
-
- </style>
-
- </head>
-
-
- <body>
-
- <div class="main">
-
- <figure>
- <img src="img/loading.png" data-src="img/1.png">
- <figcaption>I am a caption </figcaption>
- </figure>
-
- <figure>
- <img src="img/loading.png" data-src="img/2.jpg">
- <figcaption>I am a caption </figcaption>
- </figure>
-
- <figure>
- <img src="img/loading.png" data-src="img/3.jpg">
- <figcaption>I am a caption </figcaption>
- </figure>
-
-
- <figure>
- <img src="img/loading.png" data-src="img/html5.png">
- <figcaption>I am a caption </figcaption>
- </figure>
-
- <figure>
- <img src="img/loading.png" data-src="img/1.png">
- <figcaption>I am a caption </figcaption>
- </figure>
-
- <figure>
- <img src="img/loading.png" data-src="img/2.jpg">
- <figcaption>I am a caption </figcaption>
- </figure>
-
- </div>
-
- <script>
- $(document).ready(function(){
- $('img').unveil(600);
- }); // ready
- </script>
-
- </body>
- </html>
-
if the codes to messy , see it on pastebin .
now when going through the documentation , i saw a few usages of this pluggin that i did't quite understand .
- eg . $( "img" ).trigger( "unveil" );
what would that line really do ?? what more can i do , than just lazy load with this pluggin ??
its a pritty small pluggin , just liek 50 lines of code , but seems to be pritty handy .