Jump to content
Search Community

fade sections in and out and split image using scrolltrigger

dagda1 test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

This is my first time using greensock and it is fair to say I have failed at what I want to achieve.

 

I am very baffled by the second string argument to both `start` and `end`.

 

e.g. `top top`.  I get what the first top means but not the second.

 

In the codesandbox, I want the sections to apply and remove opacity as they scroll in and out and I want the 2 divs to split apart when I scroll into the second section but it is not working.

 

Here is a codesandbox

Link to comment
Share on other sites

Hi @dagda1 welcome to the forum! 

 

It is hard to wrap your head around it at first, but it is fairly simple, your codesanbox doesn't load for me, but I'll try my best to explain how the strings work. 

 

You can split them op into two sections, the first word has everything to do with your trigger element, eg trigger: "#myElm" and the second one has to to with the viewport (the browser window). I find it best to always use markers: true, in my ScrollTrigger object, because this will visualise the markers and makes it even easier to understand. 

 

so, "top top" means, when the top of my trigger element ("#myElm") hits the top of the browsers viewport do something until end: "bottom top", translates to: when the bottom of "#myElm" hits the top of the browser window and this will animate something (if scrub is true) for a distance of the height of "#myElm".

 

 

here is a simpel example. You can see that the start and end makers are on top and on the bottom of the element and the viewport makers are on top of each other at the top of the viewport

See the Pen GRYWqNe?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen

 

This animation is really fast, because the element isn't that big, so what we can do is add some pixel distance to the end marker, so we do bottom+=3000px this will set the end to the bottom of the element + 3000px. If you don't care about the height of the element you could set it to top+=3000px or just set it as 3000px, ScrollTrigger is smart and just tries to convert what you type there to what it needs. Hope it helps and happy tweening! 

 

See the Pen PoypzWv?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen

  • Like 2
Link to comment
Share on other sites

There are a few issues with your code.

 

ScrollTrigger uses the normal browser scroll to do all It's calculations, so if you disable scroll on the body and put it on another object you have to know 100% what you're doing and then set a custom scroller to have ScrollTrigger use that as the scroller (check the docs https://greensock.com/docs/v3/Plugins/ScrollTrigger) When starting out I would strongly discourage hacking the normal scroll behaviour and just let the browser handle all it scroll (see your CSS for what I've removed) 

 

When you define ScrollTrigger in a timeline all you do is create an object called scrollTrigger: {} and put all your settings in there directly. you had set it up like this scrollTrigger: {ScrollTrigger.create({...})} which is not correct and creates two ScrollTriggers at once. 

 

You almost never need a .fromTo() animation. Your elements are either already at their start position or their end position, so at .to() or .from() is all you need. 

 

I would advise you to remove ScrollTrigger at first! This seems counter intuitive, but ScrollTrigger is just animating something on scroll, so just focus on the animation at first and only when you're happy with the animation add ScrollTrigger back in. 

 

I've removed all other ScrollTriggers and just have the one where the text moves to the left and right. Let's start there and slowly build up from that. What do you want this text to do? 

 

See the Pen yLRMgba?editors=0100 by mvaneijgen (@mvaneijgen) on CodePen

  • Like 2
Link to comment
Share on other sites

Thank you for taking the time to do this.

 

I am trying to create what is happening in this website where the image splits in half (I've used divs in the codepen but images in reality).  

The image splits in half and is then pinned at the sides.


Also, the sections fade in and out based on scroll position. 

Link to comment
Share on other sites

Hi,

 

I think the best approach here is to forget about ScrollTrigger for now and focus just on getting the image split animation first, then tie ScrollTrigger to it. ScrollTrigger just updates the progress of a specific animation based on the scroll position, nothing more.

 

I'd encourage you to create a working animation first and then use ScrollTrigger in it. If you have any issue with creating the animation, just post back and we'll help you as much as we can with that.

 

Happy Tweening!

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...