Jump to content
GreenSock

xxboonexx

Draggable start drag autromatically

Go to solution Solved by OSUblake,

Recommended Posts

I am trying to make an instance of draggable start without the click event.  I need it to immediately begin tracking to the mouse when it loads. Any ideas?

See the Pen oNZVNjr by xxboonexx (@xxboonexx) on CodePen

Link to comment
Share on other sites

  • Solution

Hi, you're going to need some type of event to trigger it. And you will probably need to move it where ever the mouse is.

 

var myDrag = new Draggable("#dragger");

window.addEventListener("mousemove", startDrag);

function startDrag(e) {
	window.removeEventListener("mousemove", startDrag);
	
    gsap.set("#dragger", {
		x: e.clientX,
		y: e.clientY
	});
  
	myDrag.startDrag(e);
}

 

  • Like 2
Link to comment
Share on other sites

49 minutes ago, OSUblake said:

Hi, you're going to need some type of event to trigger it. And you will probably need to move it where ever the mouse is.

 


var myDrag = new Draggable("#dragger");

window.addEventListener("mousemove", startDrag);

function startDrag(e) {
	window.removeEventListener("mousemove", startDrag);
	
    gsap.set("#dragger", {
		x: e.clientX,
		y: e.clientY
	});
  
	myDrag.startDrag(e);
}

 

Perfect, thanks so much!

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