0

I have a custom module that does only one thing and that is lazy loading images. For the lazy loading part, I'm using jQuery Lazy (http://jquery.eisbehr.de/lazy/)

My Problem: Sometimes the jQuery Lazy loading library is loaded BEFORE jQuery which results in console errors.

Hereunder my code:

requirejs-config.js:

var config = {
   map: {
    '*': {
        jqlazy: 'Fks_Custom/js/jquery.lazy.min',
        }
   },
   shim: {
      jqlazy: {
          deps: ['jquery']
      }
   }
};

Template; lazyload.phtml:

 <script>

 require([
    "jquery",
    'jqlazy'
    ], function($) {

    $(".lazy").Lazy({
        enableThrottle: true,
        throttle: 250
    });

});

</script>

Is there something wrong?

1 Answer 1

0

You can try this in your .phtml template:

<script>

 require([
    "jquery",
    'jqlazy'
    ], function($) {

 $(document).ready(function(){
    $(".lazy").Lazy({
        enableThrottle: true,
        throttle: 250
    });
 });
});

</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.