Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7178521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:56:15+00:00 2026-05-28T16:56:15+00:00

$(window).scroll(function() { hash = $(‘.layer:in-viewport’).attr(‘id’); if ( currentHash != hash ) { // fires

  • 0
$(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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:56:15+00:00Added an answer on May 28, 2026 at 4:56 pm

    Hi Matt your problem seems to be the relative url in the pushstate call. Here’s what I changed:

    I added a variable to the beginning of the js document to capture the initial browser location:

    var initialHref = location.href;
    

    Then I made a relevant change to the “url” var in the pushstate call:

    if ( currentHash != hash ) {
    
        // ADDED: BUILD THE FULL URL AND APPEND HASH
        if(location.href == initialHref){
            url = location.href + sl + hash;
        }else{
            url = location.href.substr(0, location. href.lastIndexOf("/")) + sl + hash;
        }
    
    
        // If history API is available
        if ( history && history.pushState ) {
    
            if ( !historyBack ) {
                //console.log(url);
                window.history.pushState(hash, hash, url);
            }
    
        // Fallback to top.location.hash
        } else {
    
            $(window).off('hashchange', goToHash);
    
            top.location.hash = url;
    
            setTimeout( function() {
                $(window).on('hashchange', goToHash);
                }, 0);
        }
    
        currentHash = hash; 
    }
    

    The reason the first image isn’t loading in is it doesn’t actually exist.

    Seems to work fine now in Firefox etc. Live version here for you: http://vdotgood.com/stack/test.html

    EDIT: Funnily enough in the Firefox dev docs is says it can be a relative URL but that doesn’t seem to work…odd.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the $(window).scroll(); to specify a function to be call for when the
$(window).scroll(function(e){ if($(this).scrollTop()>=400) $('#jtop').show('slow'); if($(this).scrollTop()<400) if($('#jtop').width()) $('#jtop').hide('slow'); }); I'm using the function to determine if
$(window).scroll(function() { $('#myElement').css('top', $(this).scrollTop() + px); }); works great, but what if I want
I'm using the $(window).scroll(function() to set classes on the navigation of a site. When
I have a floating header and it shows with the following code: $(window).scroll(function ()
<script type=text/javascript> function pageLoad() { var $scrollingDiv = $(#scrollfix); $(window).scroll(function () { if ($(window).scrollTop()
I have put a scroll handler to my page : $(window).scroll(function() { ... });
I'm looking for something to this effect: $(window).scroll(function(event){ if (/* magic code*/ ){ //
So I want to do a couple of things on scroll with jQuery... $(window).scroll(function()
Specifically, I am talking about this code: $(window).scroll(function(){ var loc = $('html').offset().top; }); To

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.