Jump to content
Search Community

throwProps DOM manipulation based on the rotation value

j4ck test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts



Based on the rotation property of the wheel, I'd like to change the HTML content based on the segment that it lands on. I've used the rotationSnap var but I'm unsure how to call it's value based on the end position to then alter the HTML.


I'd also ideally like to set-up each segment as a separate div so I can then easily place content into them such as the title of the colour etc.


I'm fairly new to GSAP (and js to some extent) so I would like a bit of guidance on how achieve this.


Many thanks!

Link to comment
Share on other sites

Hey @Jonathan thanks for the welcome!


So to be more specific, the HTML that I would want to replace depending on the wheels endValue is everything in the ID of content (in the attached CodePen). When the user spins the wheel and it lands on another colour, the content in the h1, p and the href of the a tag would change accordingly. 


I hope this is more clear!

Link to comment
Share on other sites

This can get a little tricky and I'm sure there are many ways to do it.

My basic approach would be to store your data in an array. Use the wheel to generate an appropriate index based on its rotation when it stops spinning.

Since you have 6 segments in your wheel I created an array with six items.

The wheel can be spun in a positive direction and land on increments of 60 thanks to your snap function.

When the wheel is done spinning I take the actual rotation which could be a big number and mod 360 it to get a value between 0 and 360. I then take that number and divide it by 6 to get the index that I need.


please see the demo here:

See the Pen xrRjVy?editors=0010 by GreenSock (@GreenSock) on CodePen



If you allow the wheel to spin in the other direction and generate values less than 0, my equations blow up. If you need bi-directional limitless spinning you may need to seek help from someone else. Hopefully my demo gives you some ideas.


As far as building the wheel out of separate divs and all the css for that, that's a challenge I'll have to pass on as well. Search CodePen for pie charts. I found this pretty quickly:


See the Pen fEish by AtomicNoggin (@AtomicNoggin) on CodePen


I suspect using a single SVG for the wheel will save a lot of trouble.








  • Like 3
Link to comment
Share on other sites

Many thanks for your reply @Carl , this have given me an amazing base to work upon!


Ideally I would like to have it spin both ways and generate negative values but if it's not possible that it's something I can work around.


Like how you have changed the h1 using: 



Could I also do this with the anchor tag? I tried putting all links into an array like you did for the h1 using the same markup but unfortunately it didn't work.



Link to comment
Share on other sites

yeah, after sleeping it was pretty easy to go the other way. when there is a negative index you just need to subtract from the length of the array.


if (index < 0) {
  //negative index needs to wrap around
  index = (people.length) + index;



I updated the demo with some names on the wheel so it is much easier to tell if it is working:


See the Pen xrRjVy?editors=0010 by GreenSock (@GreenSock) on CodePen




  • Like 3
Link to comment
Share on other sites

Amazing @Carl, that's awesome. There's still a minor issue however how you're only able to go 'backwards' one rotation before it locks again. Any thoughts?


Many thanks for everyones input thus far! 

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