Jump to content

Guest DE.

Change HTML value based on dragging position

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

Initially, the green box is moving from left to right and the counter number is decreasing from 47,650 to 14,000 but after green box reach to right position, the drag feature is enabled and user can drag green box from right to left and vice versa. The problem I am facing is after dragging, the counter number should also increase and decrease respective to the position of greenbox. Like if I drag greenbox from right to left, the value of counter should increase from 14,000 to 47,650 and if I drag from left to right, the value should decrease from 47,650 to 14,000. Any help will be appreciated

See the Pen oNvpMeX by piyushwalia (@piyushwalia) on CodePen

Link to comment
Share on other sites

Hey Pro C and welcome to the forums. Thanks for being a club GreenSock member!


You were very close. The main thing is that you need to change your shadowUpdate function. 

function shadowupdate() {
  console.log(this.x / 920);
  var value = 33650 - (33650 * this.x / 920) + 14000;
  document.getElementById("eclipse__counter").innerHTML = formatter.format(value);

I also changed your draggable a bit:

Draggable.create(".eclipse__drag--sun", {
  type: "x",
  edgeResistance: 0.9,
  bounds: { minX: 0, maxX: 920 },
  throwProps: true,
  overshootTolerance: 0,
  onDrag: shadowupdate,
  onThrowUpdate: shadowupdate

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


If you don't want the number to ever be able to be outside of your bounds, set the edgeResistance to 1.

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