1

I would like to modify javascript trigger 'ready' and 'ajaxStop' for Lazy Load plugin

$(document).ready(function() {
    $("img.lazy").lazyload({
        threshold:50,
        skip_invisible : false,
        effect: "fadeIn"
    }).removeClass("lazy");
});

$(document).ajaxStop(function() {
    $("img.lazy").lazyload({
        threshold:50,
        skip_invisible : false,
        effect: "fadeIn"
    }).removeClass("lazy");
});

It should be something like this:

    $(document).any-possible-function(function() {
        ...
    });

To minimize the code, Please help with modification.

1 Answer 1

2

Not sure what do you want to achieve but to minimize your code write it like this:

var lazyLoader = function() {
    $("img.lazy").lazyload({
        threshold:50,
        skip_invisible : false,
        effect: "fadeIn"
    }).removeClass("lazy");
};

$(document)
    .ready(lazyLoader)
    .ajaxStop(lazyLoader);
Sign up to request clarification or add additional context in comments.

4 Comments

I've found that can use $(document).each(function(), does 'each' it mean it should work for each function, however i tried and it doesn't work
The .each method is for every element in your selection so in your case the selection would be document. You have to clarify what you want to do.
I would like script start lazyload() for any document trigger i.e: $(document).*(function() (not only for ready or ajaxstop)
I think there are too much functions in jQuery as it would make sense to do this automatically. It is possible to read all $ methods available and attach the layy function but you would end up with more code as if you attach them manually to all methods needed. And manually you can control on which method you actually bind your lazyloader.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.