Jump to content
Search Community

How to make a div scroll horizontally and vertically simultaneously?

Jean-francois test
Moderator Tag

Go to solution Solved by Jean-francois,

Recommended Posts

Hello! 

 

I'm working on enabling a div to "pan" — that is, to scroll in both vertical and horizontal directions simultaneously. This functionality is particularly relevant for trackpad users. For a clearer understanding of what I'm aiming for, please refer to the attached demo video.

 

At present, I've managed to implement a grab feature, but the scrolling is restricted to either vertical or horizontal movement, not both.

 

I realize that overriding the default scrolling behavior might require JavaScript, considering it's the standard way these interactions are handled.

 

Despite my efforts, I've hit a roadblock. I'd greatly appreciate any guidance or assistance you can offer on this matter.

 

Thank you:)

 

PS: I had to add a timeout in the codepen demo to fix a weird bug so it needs a second to load.

See the Pen poBVRzM by d00td00t (@d00td00t) on CodePen

Link to comment
Share on other sites

Hi @Jean-francois and welcome to the GSAP Forums!

 

Creating something like that is not really simple but I think the best option here could be to use the Observer Plugin and the callbacks it offers such as onChangeX, onChangeY, onUp,  onDown, onLeft and onRight:

https://gsap.com/docs/v3/Plugins/Observer/

 

You beat me and found a solution, but still Observer could be helpful and you could take a look at it.

 

Anyways, is great to hear that you were able to solve it 🥳

Happy Tweening!

  • Thanks 1
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...