Jump to content
Search Community

Draggable: Proper way to tween a div that is being dragged

tauab test
Moderator Tag

Go to solution Solved by Carl,

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

Hey guys,

 

Was wondering how to best approach tweening a div that has a Draggable function associated with it, so that it does not mess up any of the values that is being calculated for dragging/scrolling etc.

 

Let's say I wanted to anchor to a particular section automatically by using tweenmax but also wanted to preserve the Draggable features like grabbing and scrolling.

 

More specifically, how would I tween the div with class"box" in the code pen?

 

Any help would be greatly appreciated.

 

Thanks! 

See the Pen GHtaK by anon (@anon) on CodePen

Link to comment
Share on other sites

  • Solution

H,

 

Thanks for the CodePen demo. Little stuff like that saves us lots of time.

 

I think the big trick is just making sure the Draggable interactions properly kill whatever scrolling might be currently running.

I added a little button that scrolls to 400px slowly. 

 

//cache #demo so that we only find it once
var $demo = $("#demo")


Draggable.create($demo, {
  type:"scrollTop",
  bounds:$demo,
  edgeResistance:0.65,
  //kill scroll tweens on press 
  onPress:function (){
    TweenMax.killTweensOf($demo)
  },
  throwProps:true
}
)


$("#scroll").click(function() {
  TweenMax.to($demo, 4, {scrollTo:400})
})

http://codepen.io/GreenSock/pen/gAJdn

 

Notice you can drag while the button-initiated scroll is running and click the button while a throw-tween is running.

 

If there is a use-case that isn't working, please let us know.

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