Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Thales Ribeiro

Rotate on Mouse

Recommended Posts

I'm trying to use greensock for an animation I have to rotate a number of objects around the mouse.
 

Anybody has any idea on how to use this code and be able to rotate multiple objects around the mouse by just one class? 

See the Pen mmKPaY by thalesribeiro (@thalesribeiro) on CodePen

Link to comment
Share on other sites

GSAP is not going to help you out much here. You have to find the angle from the absolute transform origin to the mouse for every thing you want to rotate.

 

var dx = mouse.x - origin.x;
var dy = mouse.y - origin.y;
    
var transform = "rotate(" + Math.atan2(dy, dx) + "rad)";
element.style.transform = transform;

 

So something like this, although I'd probably use canvas for this many elements.

 

 

 

  • Like 4
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.
×