6

Instead of lazy loading image alone,i need to add lazy load for entire div element in my page.

Can you anyone help me out with some plugins or own js code.

mano
  • 374
  • 1
  • 4
  • 11
  • Check this out: [jquery lazy load content in div](https://stackoverflow.com/questions/21219283/jquery-lazy-load-content-in-div) – Mathews Mathai Mar 21 '18 at 05:47

1 Answers1

3

You can use this plugin. Its helpful and will do the trick for you.

https://github.com/emn178/jquery-lazyload-any

Just use this script as shown in documentation.

<div id="you-want-lazyload">
  <!--
    <p>Anything you want to lazyload</p>
  -->
</div>

JavaScript

$('#you-want-lazyload').lazyload(options);

Hope it will help.

Edit

HTML Attribute Style

<div id="you-want-lazyload" data-lazyload="&lt;p&gt;Anything you want to lazyload&lt;/p&gt;">
</div>

Script Style

<div id="you-want-lazyload">
  <script type="text/lazyload">
    <p>Anything you want to lazyload</p>
  </script>
</div>
SRK
  • 3,476
  • 1
  • 9
  • 23
  • the value for child elements of div tag will be binded from datasource. but using this plugin inner elements should be commented . – mano Mar 21 '18 at 05:55
  • This is just an example I have given, You can check the documentation there are different way of doing this. Let me update my answer for you. @mano – SRK Mar 21 '18 at 05:56
  • fine. for me its works with script style. thanks a lot man @Smit Raval – mano Mar 21 '18 at 06:43
  • This is a jQuery example. Not a javascript example. It should say as much. Newer users will find this answer confusing. – Bangkokian Jul 07 '22 at 05:44