Jump to content
Search Community

Parallax effect with img tag, not background image

ghisleouf test
Moderator Tag

Go to solution Solved by ghisleouf,

Recommended Posts

Hi guys,

 

I'm back with another use case and another question.

I'm trying to reproduce this parallax effect : https://tympanus.net/Tutorials/SmoothScrollAnimations/ (that I could find from another question on the forum).

 

But ... I have to use img tag instead of background image.

In my example, I could position the img tag with the parent element padding trick (see its initial position set vs the debug green overlay pseudo element), and I assume I know this padding ratio.

Unfortunately, I can't find the correct ScrollTrigger settings to make it work properly.

 

If you have any suggestion or a debug idea, that's wold be awesome.

 

Thanks a lot for your help.

 

++

 

 

See the Pen WNZZWQd by ghislefou (@ghislefou) on CodePen

Link to comment
Share on other sites

Hi @OSUblake

 

Thanks again for your quick answer.

I started from this example on the forum and I used this calculation on another parallax effect but I have to admit that could not make it work in my example.

 

I have updated it to activate the same technique on my example and as you will see, the y-axis positioning is not correct:

If you have any idea, that would be awesome.

 

Thanks again.

Link to comment
Share on other sites

8 hours ago, ghisleouf said:

I have updated it to activate the same technique on my example and as you will see, the y-axis positioning is not correct:

 

I'm not sure I understand by what you mean the positioning is not correct. If you're looking to move it in the opposite direction, you could just do a fromTo animation.

 

gsap.fromTo(img, {
      y: () => section.offsetHeight - img.offsetHeight,
    }, {      
      scrollTrigger: {
        trigger: section,
        scrub: 0.5,
        invalidateOnRefresh: true
      },
      y: 0,
      ease: "none"
    });

 

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