Jump to content
Search Community

Rotate Element Clicked with Jquery & GSAP

PapaDeBeau test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

       $(this).on("click", function(){
                gsap.to($(this), .5, {rotation:360, transformOrigin:"50% 50%"});
            });

JQuery sess the $(this) and recognizes the click and runs but in the function it does not see the $(this) and I get an error:
 Invalid property rotation set to 360 Missing plugin? gsap.registerPlugin().

I am loading GSAP by a script tag like this: 

 

<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>

The GSAP will work if it's outside of the click function but will not work in the click function. How do I get GSAP to see the object I clicked on? Thanks

Link to comment
Share on other sites

Thank you, Jack, for your replay. Ok so I understand a little more, but how would I make it so  whatever element I clicked on that would rotate? This is essentially what I am trying to do. So I just have one THIS button and the rotation is applied to every element I click. This must be possible right? Thanks

Link to comment
Share on other sites

That is what @GreenSock example allows right?

 

I've just copied the element a bunch of times and it seems to do exactly what you're describing, are we missing something? Otherwise can you provide a minimal demo with the setup you're using, so it will be more clear what is going on.

 

See the Pen ZEVbgGz?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen

Link to comment
Share on other sites

  • Solution
On 8/26/2023 at 10:31 PM, PapaDeBeau said:

What if we want it to spin ANY div it clicks on

 

Then query for a div. I don't really thing you want any div on the page, but you can do it. This has nothing to do with GSAP, this is pure Javascript or in your case jQuery. 

 

See the Pen OJryKpB?editors=1011 by mvaneijgen (@mvaneijgen) on CodePen

 

Or you can query for all the elements that you want to be clickable, but you'll find that then it will be much easer to just give the element you want to click a specific class in your HTML.

 

See the Pen mdaeNWL?editors=1011 by mvaneijgen (@mvaneijgen) on CodePen

 

Keep in mind that as per forum guidelines, we like to scope this forum to GSAP related questions

 

 

  • Like 2
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...