Jump to content
Search Community

Draggable knob rotation limit output to 0 - 360 deg

Damo 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

Hello,

 

Sorry if this is a simple one but just wondered if anyone could help me with this demo:

See the Pen eDxKh by GreenSock (@GreenSock) on CodePen

 

I'm trying to limit the output to 0 - 360 the dial can have unlimted rotations backwards and forwards but not show a negative value, currently if the first rotation is anti clockwise the output is a negative value.

 

Thanks in advance and thanks to Carl for the initial demo.

Link to comment
Share on other sites

  • 2 weeks later...

Hello,

 

I now have the membership and the ThrowProps plugin :-)

 

With regards using: TweenMax.to(knob, 1, { rotation: deg, ease: Linear.easeNone });

 

I'm passing value between 0-360 to set the knob rotation, however after multiple user rotations of the knob the actual knob position is greater than 360, this will result in the knob spinning back around several times to settle between the specified value of 0-360.

 

What is the best way to set the knob rotation in this scenario to prevent this behavior?

 

Many Thanks

 

Damien

Link to comment
Share on other sites

Hello Damo,

 

Have you looked into using the directionalRotation which is part of the CSSPlugin

 

Check out this example:

See the Pen ihylp by jonathan (@jonathan) on CodePen

 

It uses the _short concatenated to the deg parameter value, to make the plugin choose the direction for you using the shortest path.

function updateRotation(deg) {
    TweenMax.to(knob, 1, { rotation: deg + "_short", ease: Linear.easeNone });
}

Taken from the CSSPlugin Docs:

 

directionalRotation - tweens rotation in a particular direction which can be either clockwise ("_cw" suffix), counter-clockwise ("_ccw" suffix), or in the shortest direction ("_short" suffix) in which case the plugin chooses the direction for you based on the shortest path. For example, if the element's rotation is currently 170 degrees and you want to tween it to -170 degrees, a normal rotation tween would travel a total of 340 degrees in the counter-clockwise direction, but if you use the "_short" suffix, it would travel 20 degrees in the clockwise direction instead.

 

Does that help? :)

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