Jump to content
Search Community

Horizontal Scroll whilst detecting elements in Viewport

JoshPS test
Moderator Tag

Recommended Posts

Hi,

 

I am having a few issues with Horizontal Scrolling and then detecting when an element comes in sideways.

 

 

What I am trying to achieve with my codepen is when the next '.panel' comes atleast 15% into the viewport via horizontal scroll I want the '.inside-panel' to turn red. I have found examples similar but they only show examples using vertical scroll. Similar posts but using vertical scroll.

 

 

Thanks all

 

See the Pen MWQqQKp by Josh-Millard (@Josh-Millard) on CodePen

Link to comment
Share on other sites

Hi @Cassie,

 

Thanks again for previously for your help - I've hit another problem!

 

For some reason my elements are 'skating' from right to left, not during the scroll.

 

For example - Similar to my codepen above, where the divs are changing colours, I am having an image start at -30% then as they enter the viewport, I want them to move to 0%, What I have so far works BUT I am getting a skating effect so they just seem to slide from their starting position to end position. Hope this makes sense?

 

const sections = gsap.utils.toArray(".meet-the-team div.member");

let maxWidth = 0;
sections.forEach((section) => {
  maxWidth += section.offsetWidth;
});

/**
 * Horizontal Scroll for Team Members
 */
let memberAnimation = gsap.to(sections, {
  scrollTrigger: {
    trigger: ".meet-the-team",
    start: 'top top',
    end: () => `+=${maxWidth - window.innerWidth }`,
    scrub: 1,
  },
  x: () => `-${maxWidth - window.innerWidth}`,
  ease: "none",
});

/**
 * only animate when the img comes into viewport
 */
gsap.utils.toArray( 'img.member' ).forEach(el => {
  gsap.to( el, {
    scrollTrigger: {
      trigger: el,
      containerAnimation: memberAnimation,
      start: 'left 85%',
      end: 'center 20%',
      scrub: true,
    },
    x: "-30%",
    ease: "none",
  });
});

 

Link to comment
Share on other sites

Thanks again for your reply,

 

I managed to resolve this - I actually had left 'transition: all 0.6s ease' on the element I was moving which was causing it to drag slowly then skate from position A to position B!

  • Like 2
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...