Jump to content
Search Community

walpolea

Members
  • Posts

    7
  • Joined

  • Last visited

Posts posted by walpolea

  1. You're definitely not wrong there about smooth scrolling a page, some really gut-wrenching implementations out there. Though I'm very impressed in ScrollSmoother maintaining accessibility and experience consistency across devices, which is what led to me trying it out.

    • Like 2
  2. Thank you for confirming that. I've got this in place and working for the moment, however it's poor practice to click-jack a link at all, so I may switch to a button.

     

    document.querySelectorAll("a[href^='#']").forEach((a) => {
      a.addEventListener("click", (e) => {
        e.preventDefault();
        ScrollSmoother.get().scrollTo(a.hash, true);
        window.history.pushState({}, "", a.hash);
      });
    });
    
    window.addEventListener("load", (e) => {
      if (window.location.hash) {
        ScrollSmoother.get().scrollTo(window.location.hash, true);
      }
    });

     

    • Thanks 1
  3. Thanks, that does work if I were to change the link to a button and not use the default behavior of a jump link (which adds the hash to the url bar and such). I can go this route as a last resort, but I think I would prefer to have a solution that allows that native behavior of a jump link to work.

  4. I think it's less performance problems and more that the refresh stops the existing scroll tween, causing a stuttering effect. Given the nature of lazy-loaded images (which load as you scroll them near the viewport) I'm not sure there is much to be done, perhaps wait until the velocity is closer to 0 like this:

    let needsToRefresh = false;
    
    document.addEventListener('lazyloaded', function(e){
      needsToRefresh = true;
      refresh();
    });
    
    function refresh() {
      if( needsToRefresh && smoother.getVelocity() < 0.01 ) {
        ScrollTrigger.refresh();    
        needsToRefresh = false;
      } else if( needsToRefresh ) {
        requestAnimationFrame(refresh);
      }
    }

    Still not the best experience. Definitely the killer feature would be for gsap to somehow not stop the scrolling tween as ScrollTrigger refreshes.

  5. I ran into the same issue with a tabbed component changing the content height. The only solution I found was to dispatch a resize event which ScrollTrigger refreshes values on pretty gracefully.

    window.dispatchEvent(new Event("resize"));

     

    This also works as images lazily load in, but there is some undesired jank as things recalculate while the scrolling is mid-tween

    document.querySelectorAll("img[loading=lazy]").forEach((i) => {
      i.addEventListener("load", (e) => {
        window.dispatchEvent(new Event("resize"));
      });
    });
    • Like 1
×
×
  • Create New...