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

Option autoInit = false seems to have no effect? #31

Open valnub opened 9 years ago

valnub commented 9 years ago

In the sourcecode for lazy-load-xt I see this:

    $(document).ready(function () {
        triggerEvent('start', $window);

        $window
            .on(options.loadEvent, initLazyElements)
            .on(options.updateEvent, queueCheckLazyElements)
            .on(options.forceEvent, forceLoadAll);

        $(document).on(options.updateEvent, queueCheckLazyElements);

        if (options.autoInit) {
            initLazyElements(); // standard initialization
        }
    });

So, if options.autoinit equals false, then initLazyElements() will not be called on document.ready():

        if (options.autoInit) {
            initLazyElements(); // standard initialization
        }

BUT it will be called on body.load event:

        $window
            .on(options.loadEvent, initLazyElements)

At this point there is no check if options.autoinit is true or false?

What's the point of that option if initLazyElement() is still triggered on body.load?

erin-dot-io commented 9 years ago

I am also trying to understand how to use autoInit: false as it doesn't seem to do anything...

dryabov commented 9 years ago

Try to overwrite updateEvent as well:

$.lazyLoadXT.autoInit = false;
$.lazyLoadXT.updateEvent = 'orientationchange resize scroll touchmove focus';
dennisbaum commented 9 years ago

the same for me too. the above lines before jquery.ready doesn't have effect. images are lazy loaded.

alonsoysa commented 8 years ago

Just had the same issue. It seems like this line:

loadEvent: 'pageshow', // check AJAX-loaded content in jQueryMobile

should have been blank by default

loadEvent: '', // check AJAX-loaded content in jQueryMobile

Seems to work after that.

kapajohn commented 8 years ago

I know that my answer comes a little bit late but i hope that someone will be helped. If you don't want auto init lazyload (default behaviour) you'll need to change the option to false before the document is ready. Then you'll have to init it manually using selectors. $.extend($.lazyLoadXT, { autoInit: false }); $(document).ready(function () { $(container).find('selector').lazyLoadXT();

philschoefer commented 8 years ago

I can confirm kapajohns solution. In my case I'm using WordPress Sage Theme as a boilerplate and jQuery is in compatibility mode. Therefore my code was:

jQuery.extend(jQuery.lazyLoadXT, { autoInit: false, loadEvent: '' });

As you can see I also had to follow @alonsoysa solution and overwrite the load event for this to work.

This needs to be placed after lazyLoadXT is added to the dom, but before domready is fired. So if you have some sort of domready function, place it just above, for example.