thybag / PJAX-Standalone

A standalone implementation of Pushstate AJAX, for non-jquery webpages.
203 stars 42 forks source link

Lazy Loading Images #21

Closed rookietect closed 10 years ago

rookietect commented 10 years ago

Hi Carl,

I am trying to get this Lazy Load Plugin - http://dinbror.dk/blog/blazy/ - working. I tried the new branch with the following code:

pjax.connect({
    'container': 'pjax',
    'parseJS': true
});

I included the following code above <?php $title :

    <script type="text/javascript"> /* blazy.js inline code */ </script>
    <script>
        ;(function() {
            // Initialize
            var bLazy = new Blazy();
        })();
    </script>

Didn't work — is this approach too optimistic?

Thanks a lot, rookie

thybag commented 10 years ago

Hello,

I will try and have a proper look at this tomorrow.

My initial guess would be that the ideal way to use the plugin would be to include & set up the bLazy script outside of the container used by PJAX, then rather than using inline js just adding a bLazy.revalidate(); call in to the PJAX complete callback.

Granted, I've yet to have a proper look at the code.

Thanks, Carl

rookietect commented 10 years ago

Hi Carl,

an update on this would be very much appreciated.

Thanks, rookie

thybag commented 10 years ago

Hello,

I've just had a test and it appears to work as expected for me?

The code I'm currently using is:

    var bLazy;

    // PJAX links!
    pjax.connect({
        'container': 'content',
        'success': function(event){
            bLazy.revalidate();
        },
        'ready': function(){
            bLazy = new Blazy({
                success: function(ele){console.log("image loaded");}, 
                error: function(ele, msg){console.log("image failed to load");}
            });
        }
    });

The blazy library itself is added in the head of my test page.

Does that help at all? or was the issue that you only wanted blazy loaded and running on a particular page within your site?

thybag commented 10 years ago

Not heard back on this in a while so will assume its all fixed :)