ressio / lazy-load-xt

Lazy load XT is a jQuery plugin for images, videos and other media
http://ress.io/lazy-load-xt-jquery/
MIT License
1.36k stars 245 forks source link

Refresh lazy load when changing window size? #22

Open goslingo opened 9 years ago

goslingo commented 9 years ago

Hello,

Is there an easy way of making Lazy Load refresh all images when the browser window reaches a certain size?

Currently (using the responsive images add-on) if you load the page with a narrow window it will load small images. Obviously if a user increases the browser width it would be great to load in higher res images.

Thanks, Oli

ghost commented 9 years ago

I'd be very interested to find this out too.

I was thinking maybe its possible to trigger initialization again on $( window ).resize() with checkDuplicates set to false, but I don't think that's enough to get it working reliably.

This is what I have so far:

$( document ).ready(function() {

    var resizeTimeout;

    $( window ).resize(function() {

        resizeTimeout = setTimeout(function () {
            $(window).lazyLoadXT({
                checkDuplicates: false
            });

            clearTimeout(resizeTimeout);
        }, 1000);

    });

});

This mostly does the job, but I'm seeing weird glitches with transparent PNGs (particularly on Chrome) showing a solid grey background colour instead of transparency and the blankImage (loading gif) is displayed forever.

dryabov commented 9 years ago

@ecjonathan Most likely grey background may be fixed by using CSS:

img.lazy-hidden[src] {
    background: transparent;
}
ghost commented 9 years ago

@dryabov thanks, I'll give that a try!