Ken Tang
Ken Tang

Reputation: 529

Lazy Load Images Function Modify

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.

Upvotes: 1

Views: 758

Answers (1)

Marc
Marc

Reputation: 6771

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);

Upvotes: 2

Related Questions