Forum Discussion

SupadaAmornchat's avatar
SupadaAmornchat
Community Member
3 years ago

Using Slider to Move Animated Dial

I have created an interactive dial caliper and desperately need help to figure out how to append an animated dial while dragging slider.  When the slider moves, the dial meter will move along precisely. How can I append the moving dial meter with slider?

I'd appreciate any advices.

Thank you!

 

 

 

  • You can set the dial variable equal to the slider variable, thus when the slider moves the dial will move too.

  • Thank you for your advice, Joanne. I appreciate that. I was able to make the dial meter move clockwise/counter clockwise. However the meter does not move synchronously to left/right when I drag the slider (an image attached.)

     

  • DaneJames's avatar
    DaneJames
    Community Member

    I have learned if you move the slider to fast you will have sync issues.

  • The easiest way would be to use a working dial as the thumb on a slider, but you can’t do that.

    You could give it a motion paths, one for right, and one for left, with relative starting points. Using a variable to keep track of the current value, you could move the correct direction when the slider variable changes, and update the current position variable. You would like change the slider variable as it moved, and that might slow things down too much.

    Or it might be easier to create a state for every position where you want to stop, and change the state as the slider moves.

    You could possibly use JS and GSAP to move a dial slider, but I don’t know if that would be easier for you.

     

  • Could you 'fix' the dial calliper in position and simply have the slider move the rest of the device, and so that way the dial is in the same spot and can swing as intended, but the slider is synced to the image part with measurements?

    The visual effect will be the same but it would be like the camera is 'fixed' to the dial.

  • And ofcourse i couldnot resist making it work completly.

    https://360.articulate.com/review/content/9175e7b1-c1a8-4fdb-8efd-738dcacd9761/review

    Basically the arrow is in a group with the moveable parts. The arrow itself can be targeted by GSAP without any issues. I showed that before in GSAP and groups posts. The group itself can also be targeted easily and thus moved over the x-axis.

    Selecting the elements
    let dialGroup = document.querySelector("[data-acc-text='dialGroup']");
    let arrowInGroup = document.querySelector("[data-acc-text='arrow.png']");

    For both the rotation and the x-movement are some calculations needed. The rotation is simple. For the x-movement we need a proper start and endpoint. I use shapes ( you can make them invisible in Storyline ) to get the proper start and endpoint. Especially with the Modern Player this is important as x-values tend to change when Storyline scales the content.

    /*
    Using the shapes StartPos and EndPos to get the proper x positions of the Dial Calliper
    */
    let startElement = document.querySelector("[data-acc-text='StartPos']");
    let endElement = document.querySelector("[data-acc-text='EndPos']");
    let startX = gsap.getProperty(startElement, "x");
    let endX = gsap.getProperty(endElement, "x");

    The calculation for the x-change per tick of the slider is something like this then:
    let _xChange = startX+(sliderVal*((endX-startX)/100));

    And then we can rotate the arrow and move the group with GSAP.

    gsap.to(arrowInGroup, {
    duration:0.25,
    rotation:_rotation
    });

    gsap.to(dialGroup, {
    duration:0.25,
    x:_xChange
    });

    • JoanneChen's avatar
      JoanneChen
      Super Hero

      This is brilliant! I can always learn new things from you, Math.

  • Wow. That is f#%k!ng amazing, Math!

    Totally beyond my understanding but still... wow... that's stunning.

    • MathNotermans-9's avatar
      MathNotermans-9
      Community Member

      Trial and error... the way to learn it. And then Google is your best friend to find anything needed on Javascript, selectors, query-ies and whatever comes along.

      Main thing to remember is that Storyline doesnot publish perfect clean HTML5. Not all code you find on the web will work in Storyline. Modules eg. are not supported and more caveats you will discover on your journey :-)

  • That is amazing, Math! I love how you did it. I was able to make the arrow move horizontally by using States. I animated the frame-by-frame arrow as Joanne and Walt advised. The problem with the state is it doesn't allow me to change the registration point to the bottom of the arrow. When I move the slider, the arrow looks unstable. What you did looks really neat! I will give it a try using your code.

    Thank you so much everyone for all the great information! I appreciate it.

  • Trick i used was creating a png of the arrow in which the center really was exactly aligned so no change needed for the transformation point. With GSAP you can however change it easily. Check my GSAPposts for that. Nut with an artow like this its tough to get the exaxt point