Jquery Lazyload callback

前端 未结 3 1174
小鲜肉
小鲜肉 2021-02-13 12:33

I am currently using Jquery Lazy Load and I was wondering if there is a way of making a callback when all the images from my container ended loading (when lazy load has made all

3条回答
  •  北海茫月
    2021-02-13 13:17

    In order to process on last image loaded and run code only and only when it's finished (all images loaded), you must use your handler function, as VAShhh told before, unlike the function call should only send 2 parameters, so this function is invoked with javascript call statement.

    Then you will be able to successfully retrieve the "elements_left" parameter and compare it to 0 (zero): last loaded image left. Something like this:

    function yourhandler(elements_left, settings) {
        var imageNode, container;
        if(elements_left === 0) {
           // All images were loaded.
           // Now do whatever you need with imageNode or its parents (container, etc) in order
           // to run any other Plugin
           imageNode = $(this);
           container = settings.container;
           alert('Ready to continue! Image node is $(this) and container settings.container');
        }
    }
    

    Please check this example at: jsfiddle.net/eRyww/4

提交回复
热议问题