Ad
How To Apply Lazy-loading?
I'm trying to apply a lazy-load function for my page created with this theme . The basic example of this guide does not have errors in console but lazy-load is not working. How can I modify my code? Here's an example of my div, script part is separated from my html file.
<div class="nk-portfolio-list nk-isotope nk-isotope-4-cols nk-isotope-gap-xs nk-popup-gallery">
<div class="nk-isotope-item lazy" data-filter="Abbigliamento">
<div class="nk-portfolio-item nk-portfolio-item-info-style-2 nk-portfolio-item-lg">
<a target="_blank" rel="nofollow noreferrer" href="assets/imagesPro/Abbigliamento/1.jpg" class="nk-portfolio-item-link nk-gallery-item" data-size="2747x3275"></a>
<div class="nk-portfolio-item-image"><div class="lazy" style="background-image: url('assets/imagesPro/Abbigliamento/l/l1.jpg')"></div></div>
<div class="nk-portfolio-item-info nk-portfolio-item-info-center text-center">
<div>
<div class="nk-portfolio-item-icon"><span class="pe-7s-look"></span></div>
</div>
</div>
</div>
</div>
....
</div>
$(function() {
$('.lazy').lazy({
});
});
Ad
Answer
According to the documentation of jquery lazy for loading backgrounds on other elements you should do something like this:
<!-- load background images of other element types -->
<div class="lazy" data-src="path/to/image.jpg"></div>
So you should change your code to include the data-src attribute:
<div class="lazy" data-src="assets/imagesPro/Abbigliamento/l/l1.jpg"></div>
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad