Search code examples
asp.netasp.net-mvcjquery-pluginslazy-loadinglightgallery

Lazy loading in Light Gallery


I'm using lightgallery.js (https://sachinchoolur.github.io/lightgallery.js) to develop my ASP.NET MVC project.
It seems ok to load some images which have a size of less than 1MB, but the problem here when I use about ~20 pictures (~2MB/picture), Light Gallery will load very slow.
Could you share with me some ideas to overcome this problem?
Thanks for reading.


Solution

  • Hi please check this example lazy load image.

    For more detail please check the official link -> Click me

    $(document).ready(function(){
       $("ul.jsImageUl > li img").lazy({
            effect: "fadeIn",
            effectTime: 1000
        });
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/jquery.lazy/1.7.3/jquery.lazy.min.js"></script>
    <ul class="jsImageUl">
      <li>
         <a href="#"><img data-src="https://farm4.static.flickr.com/3089/2796719087_c3ee89a730_t.jpg" width="200" height="200" alt="" /></a>
      </li>
      <li>
         <a href="#"><img data-src="https://farm1.static.flickr.com/143/321464099_a7cfcb95cf_t.jpg" width="200" height="200" alt="" /></a>
      </li>
      <li>
          <a href="#"><img data-src="https://farm1.static.flickr.com/79/244441862_08ec9b6b49_t.jpg" width="200" height="200" alt="" /></a>
      </li>
    </ul>