Jump to content


  • Posts

  • Joined

  • Last visited

Posts posted by cotton

  1. Hello


    I'm trying to get the titles on the left to add an active class when the related (by data-attributes) block on the right scroll to top.


    The blocks and titles are all found when I console.log them but the toggle class function isn't firing.

    I've tried using the onToggle: self functions but with the same result.


    I can't figure it out, what am I missing?

    See the Pen ZEMXoVg by Cottonltd (@Cottonltd) on CodePen

  2. Thanks @akapowl,


    Essentially I'm trying to get the subtitle to pin to the top, then the intro copy to pin 32px under it and both stay pinned until the end of that section hits bottom (or the start of the next section comes into view). The subtitle is dynamic so that's why that height is being calculated, to ensure the intro is always 32px below the height of it.


    I actually had the recalculations being done in the 'live' version inside a window.resize function but had commented it out. The revert() seems to do the job I just need to add that if the copy content is larger than the height of the image column, or window, it should continue to scroll, or change the grid sizing.

  3. Hello


    I'm sure this will be something fairly straightforward that I've missed but have come up against it a couple of times before.

    I'm pinning elements on scroll but on window resize the start triggers aren't recalculated to the new screen dimensions so end up off screen/overlapping with other pins.


    Any thoughts?


    Thanks in advance



    See the Pen gOjeWYq by Cottonltd (@Cottonltd) on CodePen

  4. Hello


    I've come across this a few times on recent projects and would like to see if there is a definitive way of dealing with the issue, and if it is actually an issue.

    I tend to build modular CMS sites where the content editors can build pages in whatever order they see fit using those blocks. Some of the modules will have ScrollTrigger elements in so they can have pinned/animated blocks where they need.


    As I understand, the order that the ScrollTrigger functions are placed in the scripts has a bearing on how and when these pinned sections are calculated. Now, if I am allowing the client to add a pin section in a different location each time (i.e. sometimes it will come after a horizontal scrolling carousel, sometimes before etc) how can I make sure that the order the pins are created is the order they are in the DOM? I seem to get a lot of pin starts and ends being offset incorrectly which obviously then has a knock-on effect with all the other ScrollTrigger calculations.


    Is there a really simple way to sort this that I've missed? Perhaps a ScrollTrigger.refresh(); once all content is loaded or would that cause some unsightly visual issues? Should I be adding a script tag directly into the module template code rather than in a main js file so then it is called on the page as and when needed?


    I'd offer up a pen but all the elements work fine individually, just not always when the order is more dynamic.


    Thanks in advance

  5. Hello


    Kind of following on from this thread, I'm getting an error where a section lower down the DOM is being triggered at the very top, on page load.


    To explain, I've got sections on a page which have colour attributes which are then used to change the background colour of the wrapping parent element as they are triggered. There is also a horizontal slider that does the same as each slide comes into view.


    However, on page load the first slide (orange), which is the 4th section down here, updates the wrapper background colour instead of the first DOM section.  Is it because it's a pinned element so it triggers the onEnter when the page loads and if so, can I delay that or something?


    The first section works as expected when scrolling back up the page.


    If it makes any odds the final site will be dynamic/flexible/CMS so needs to work wherever it may be placed on the page.





    See the Pen QWmRGmX by Cottonltd (@Cottonltd) on CodePen

  6. How to explain...


    I've done a pen with both states included as separate bars.

    See the Pen jOZwxZP by Cottonltd (@Cottonltd) on CodePen


    In the final site this would be a single bar but the class toggle would switch the style. So a black bar on a white background would grow to 100%, left to right then as the next section comes in the class would switch and it'd then look to be a white bar growing from left to right.


    Essentially I'm just trying to cover up the value jump back to zero and make it look more continuous.


  7. Brilliant, thanks again Jack.

    Really blows my mind how responsive, knowledgable and patient this forum is.


    The class toggle was to make the bar, which will be black and white on the full site,  look as though it fills in black from left to right and then class toggle would switch the background colours and look to fill in white left to right etc etc.


    I've tried to demonstrate it in this pen but obviously the toggle is not in the right place because it's applying the it to all the progress bars. Should I create a new scrolltrigger within that function just for this effect?


    See the Pen yLvXjJy by Cottonltd (@Cottonltd) on CodePen


  8. Hello


    I've set up a ScrollTrigger that clones an element as it's wrapper hits 200px below the window (with thanks to @Cassie)




    I'm trying to add a progress bar that shows how far you've scrolled down the cloned element and once the active element has ended it would reset the bar and begin showing the scroll progress of the next (cloned/active) element. So essentially, each cloned element is a page and as a new page comes into view the progress bar is affected/reset/ToggleClass etc.


    I've tried creating a gsap.utils.toArray to capture all the cloned elements with a ScrollTrigger.create inside it although I'm not sure if this is correct or efficient. The onLeave etc doesn't seem to be having any affect on the progress bar so something must be up.


    Any ideas?

    See the Pen rNJwwEO by Cottonltd (@Cottonltd) on CodePen

  9. I think/hope I've diluted this enough now and apologies again for making it more confusing than it ought to be.


    See the Pen YzeVaPp by Cottonltd (@Cottonltd) on CodePen


    What I'm trying to do is to change the colour of the .global_block and background colour as sections scroll into view. This will be affected by both vertical and horizontal scrolling sections. However, as you noted, the first of the horizontal sections is already in view (i.e. has past 'left center') then it is triggering the colour change on page load (the block should be black on load).


    I have three triggers working here:

    1. The one that pins the horizontal section at 'top top'

    2. one that changes the background colour (using a function that grabs the first and last slide colour attributes) as (1) reaches 'top center' and leaves at 'bottom center' — this has been removed for now to simplify the pen.

    3. one that changes the colours as each slide section reaches 'left center'


    So I guess my questions would now be:

    – Can I make the first slide section start at 'left left' while the rest start at 'left center'

    – Can I ignore the first and last slides of the horizontal section and use trigger (2) to update the colours onEnter and onLeave using another colour grab function

    – Can I make the horizontal slides only trigger when that section comes into view rather than on page load?

    – Any other options available




  10. Yeah I see it and thought I'd fixed it on the fork but actually hadn't.

    More speed, less haste required!


    I've spent a bit more time on it and the above fork now acts more like the full site.

    The log shows at 0 and the start marker shows at load, as well as the incorrect colour var, and disappears on initial scroll.


    I hope this makes more sense and apologies for going round in circles!

  11. Thanks, I see my demo was not on point.

    It certainly is off at the start in there, on the full site it starts at zero.


    I've forked the demo to include a left margin on the slides so the start point is inside the viewport and included a log of where the carousel container begins (0):

    See the Pen xxYdbaJ by Cottonltd (@Cottonltd) on CodePen


    On my local site, with the markers on the 'vertical position' ones show at first load (see screenshot attached), but then disappear to the horizontal section as soon as you begin scrolling and then reappear in place on the horizontal section. Feels like it's loading that carousel section first before the rest of the triggers are applied?



    Screenshot 2022-05-18 at 16.09.30.png

  12. Sorry @GreenSock, kitchen sink demo as I wasn't sure which element may be causing issues.

    I've reduced it down to core now and the onEnters that may be the issue. 


    I think I've narrowed it down to the following that seems to be triggering too early (line 93 in codepen):


    studysections.forEach((sct, i) => {
      const color = sct.getAttribute("data-color");
      const seccolor = sct.getAttribute("data-secondcolor");
      const textcolor = sct.getAttribute("data-text");
        containerAnimation: hCarousel,
        trigger: sct,
        start: "left center",
        end: "right center",
        scrub: true,
        onEnter: () => {
          site_wrapper.style.backgroundColor = color;
          site_wrapper.style.setProperty("--copycolor", textcolor);
          document.body.style.setProperty("--secondcolor", seccolor);
        onEnterBack: () => {
          site_wrapper.style.backgroundColor = color;
          site_wrapper.style.setProperty("--copycolor", textcolor);
          document.body.style.setProperty("--secondcolor", seccolor);

    Its just the css vars that appear to be a problem, the secondary colour change early too but the background-color inline style is fine. Perhaps it's not GSAP at all...


    It could well just be the containerAnimation problem, when you say 'pushed to the end' should I just call it at the end of the scripts or rearrange the DOM?


    Thank you.



  13. Hello


    I've got a site that when sections scroll into view the wrapper background colour is changed depending on the data-attribute on said section. There's also a horizontal scrolling section which also updates the colours as they scroll into/out of view.


    I'm using css vars to update the site text and menu/logo colours and these should be changed depending on the section data-copy attribute. However, this seems to update based on the first slide of the horizontal section on page load (there is a flash from black to white as you see the change on load), rather than as that section comes into view.


    The markers seem to be in the correct place so I'm not sure why this would be triggering on load. Is it something to do with using vars and setProperty rather than just inline hex, the ```site_wrapper.style.backgroundColor = color;``` seems to work fine and when scrolling backwards all is ok (but that is probably because the onLeave etc has been set specifically)?




    See the Pen wvyJOeQ by Cottonltd (@Cottonltd) on CodePen

  14. Hi Cassie


    Thanks for getting back, really appreciate it. Apologies it's taken a while to reply.


    This is a really lovely cloning solution. I tried to get my head around the meta-infinite scroll examples but it just wasn't sinking in. This is super simple!


    I've implemented the ScrollTrigger.create cloning the whole container of elements (because the site uses dynamic content and animation options/speed) which works great but the cloned elements aren't animating still.


    What am I missing?


    See the Pen wvyaJGL by Cottonltd (@Cottonltd) on CodePen