$(window).scroll(function() {
hash = $('.layer:in-viewport').attr('id');
if ( currentHash != hash ) { // fires it only one time when in-viewport
if ( history && history.pushState ) { // if method is available
window.history.pushState(hash, hash, url);
}
}
currentHash = hash;
});
$(".layer img").lazyload({
effect: "fadeIn",
});
I just wanted to point out that I'm trying to use the Lazy Load Plugin for jQuery when scrolling vertically through my page to lazy load all my images. I'm using the new HTML5 pushState() Method to change the url to the specific name of the container (holding the images) currently shown in the viewport.
Anyway, seems like the Lazy Load Plugin for jQuery is not compatible with the pushState() Method because right now the plugin does not work for me. It just loads the first image but then stops doing its thing.
As soon as I remove the line window.history.pushState(hash, hash, url); the plugin works fine. No errors are thrown so it's really tough debugging this and finding a solution for it.
Any ideas on that? What could I do here?
edit:
Here would be a real life example, although jsBin is not supporting the pushState Method so the bug doesn't occur on the page itself …
http://jsbin.com/obaged/3/edit
And here are real example files so the bug can be tested … http://cl.ly/1b2K2W050V0k0d2V0z0e Just uncomment the line I've mentioned above to see it working and not working!
index.htmlin any browser the images are not loaded. It says "No Image Available" on the placeholder image! As soon as you comment out the linewindow.history.pushState(hash, hash, url);in the JS file the images are loaded without a problem. Please test it again!