Jump to content
Search Community

Animation behavior breaks down

AlexandrWD test
Moderator Tag

Go to solution Solved by AlexandrWD,

Recommended Posts

Your end value gets smaller and smaller as the screen gets wider. If you turn the markers on, you'll see that eventually the end marker will go above the start marker.

 

So you'll probably need to make the functions for x and end check to make sure the area is big enough to scroll horizontally, and conditionally return a value for the appropriate size.

end: () => {
  if (thisAnimWrap.scrollWidth > window.innerWidth) {
    return "+=" + (thisAnimWrap.scrollWidth - window.innerWidth)
  }
  return ...
},

 

  • Like 2
Link to comment
Share on other sites

  • Solution

Great!

 
horizontalSections.forEach(function (sec, i) {  
 
  var thisPinWrap = sec.querySelector('.pin-wrap');
  var thisAnimWrap = thisPinWrap.querySelector('.animation-wrap');

  var getToValue = () => -(thisAnimWrap.scrollWidth - thisPinWrap.offsetWidth);
 
  gsap.fromTo(thisAnimWrap, {
    x: () => thisAnimWrap.classList.contains('to-right') ? 0 : getToValue()
  }, {
    x: () => thisAnimWrap.classList.contains('to-right') ? getToValue() : 0,
    ease: "none",
    scrollTrigger: {
      trigger: sec,  
      start: "top top",
      end: () => {
          return "+=" + (thisAnimWrap.scrollWidth - thisPinWrap.offsetWidth);
      },
      pin: thisPinWrap,
      invalidateOnRefresh: true,
      scrub: true,
    }
  });

});

Instead of the page width, I used the container width...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...