Jump to content
Search Community

Multiple Drag Instances

elrojo test
Moderator Tag

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

Is it possible to have multiple drag instances? Attached pen keeps failing...

var count;

for(count = 0; count < 2; count++){
  console.log(count)
  Draggable.create("box" + count, {
  bounds:"#container",
  edgeResistance:0.5,
  throwProps:true,
  lockAxis:true,
  onDrag:function() {
     TweenLite.to(document.getElementsByClassName("original" + count), 1, {x:this.x});
  },
  onThrowUpdate:function() {
    TweenLite.to(document.getElementsByClassName("original" + count), 1, {x:this.x});
  }
});
}

 

See the Pen RJoWEO?editors=1100 by anon (@anon) on CodePen

Link to comment
Share on other sites

3 hours ago, elrojo said:

It looks like the dragging on the y axis is enabled however. Shouldn’t lockAxis prevent this?

 

Just to be clear, "lockAxis" just means that once you start dragging in a particular direction, it'll lock movement to that axis (while that drag is occurring). So if you start dragging vertically, you won't be able to drag horizontally (until you release and start dragging again). And vice-versa. 

 

Like @PointC said, if you want to only move on the horizontal axis, set type:"x". :-)

  • 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.
×
×
  • Create New...