Jump to content
GreenSock

ochalmers

Firing events whilst dragging (draggable)

Recommended Posts

I've read through the docs but couldn't find anything relating to this in there. Is it possible for us to trigger functions or other tweens whilst dragging in draggable? For example if you started dragging, the container would tween to an opacity change or the cursor would change whilst you were dragging then change back when you let go. 

 

I've attached a pen I have that uses draggable if it's any help to work with.

 

Thanks!

See the Pen OyLEem by olichalmers (@olichalmers) on CodePen

  • Like 1
Link to comment
Share on other sites

In addition to Carl's answer/really useful links , you can do something like one of these :

 

using onPress/Release :

var  tween= TweenLite.to('#container ',0.2,{opacity:0.5,paused:true});

var draggables = Draggable.create(".box", {
onPress:function(){tween.play()},
onRelease:function(){tween.reverse()}
});

or run a function on Drag :

var DTween=1 , tween=TweenLite.to('#container ',0.2,{opacity:0.5,paused:true});

var draggables = Draggable.create(".box", {
onDrag:function(){
  if(!DTween){return false}; // return false to avoid run on Drag repeatedly
  tween.play();
  DTween=0; 
},
onRelease:function(){
  tween.reverse();
  DTween=1;
}
});

See the Pen bVpZPV by MAW (@MAW) on CodePen

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