Jump to content
Search Community

Praneet Dixit

Members
  • Posts

    6
  • Joined

  • Last visited

Posts posted by Praneet Dixit

  1. @Cassie Here it is: 

    See the Pen ZExQNaV by PraneetDixit (@PraneetDixit) on CodePen

    Steps to recreate issue:

    1. Resize window so that the width is less than 700px.

    2. On scrolling, the box should slide to center along the x-axis.

    3. Now resize the window so that its width remains within the 700px limit.

    4. On scrolling, the box will not slide perfectly into the center as the value of `containerWidth` is not updated.

  2. I have a basic gsap animation set up with matchMedia.

    ScrollTrigger.matchMedia({
        "(min-width: 700px)": function () {
            let containerWidth = parseInt(getComputedStyle(document.querySelector(".see-through")).width);
            let tl = gsap.timeline({
                scrollTrigger: {
                    / ....    
                }
            });
            tl.to(".logo-transparent", {
                x: containerWidth/2,
                scale: "0.8"
            });
        },
        "(max-width: 699px)": function () {
            let containerHeight = parseInt(getComputedStyle(document.querySelector(".see-through")).height);
            let tl = gsap.timeline({
                scrollTrigger: {
                    / ....
                }
            });
            tl.to(".logo-transparent", {
                y: containerHeight/2,
                scale: "0.9"
            })
        }
    });

    Now what I want is to update the values of containerWidth and containerHeight on each resize event. I tried adding an eventListener for resize event and updating the variables, but it still has no effect on the animation.

    Perhaps the animation is not updated on each resize unless the media breakpoints change.

    What approach can I follow for the desired effect?

×
×
  • Create New...