xxboonexx Posted June 17, 2021 Share Posted June 17, 2021 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 More sharing options...
Solution OSUblake Posted June 17, 2021 Solution Share Posted June 17, 2021 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); } 2 Link to comment Share on other sites More sharing options...
xxboonexx Posted June 17, 2021 Author Share Posted June 17, 2021 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now