Jump to content
Search Community

Set drag fluid

cleveradvertising 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

I showed you the basis for doing that in this post.

http://greensock.com/forums/topic/15370-draggable-choose-choose-only-move-to-down/?p=66819

 

The only way to really to keep the momentum going is by using a dummy draggable object, a proxy. It not actually part of the DOM. It's the same thing I've done in these examples...

See the Pen ZOgGXB by osublake (@osublake) on CodePen

See the Pen wWMYXZ?editors=0010 by osublake (@osublake) on CodePen

 

.

  • Like 2
Link to comment
Share on other sites

Why would you snap it to the middle? Look at it in full screen. Isn't that what you were trying to do?

See the Pen e83cec88a729a5bedb96124bbc443d72?editors=0010 by osublake (@osublake) on CodePen

 

The snap is caculated in the snapY function. 

function snapY(y) {
        
  // If last page, return 0
  if (lastPage) {
    return 0;
  }
    
  // Else, round the distance
  return round(y, snapDist);    
}

If you want it to snap the middle of the window, it would be like this...

function snapY(y) {
        
  // If last page, return 0
  if (lastPage) {
    return 0;
  }
    
  // Else, round the distance
  return round(y, snapDist / 2);    
} 

.

  • Like 1
Link to comment
Share on other sites

You can control where it snaps. The snapDist is the screen height, so multiply that by whatever.

return round(y, snapDist * 0.5); // 50%
return round(y, snapDist * 0.25); // 25%
return round(y, snapDist * 0.1); // 10%

if you want more control, you can use the .getDirection() method to manage the snapping behavior. Something like this...

function snapY(y) {
        
  if (lastPage) {
    return 0;
  }
           
  var direction = this.getDirection("velocity");
  var draggingUp = direction.indexOf("up") > -1;
  var draggingDown = direction.indexOf("down") > -1;
        
  // Run your logic here
  if (draggingUp) {
      
    if (y < -snapDist * 0.5) return -snapDist;
    else if (...) return ...    
    else return ...
      
  } else if (draggingDown) {
      
    if (y > -snapDist * 0.5) return 0;
    else if (...) return ...
    else return ...
      
  } else {
      return round(y, snapDist);
  }     
}

.

  • Like 1
Link to comment
Share on other sites

I'm setting a variable in the onPress callback...

onPress: function() {      
  currentDraggable = this;
}

So you could do something like this...

onPress: function() {
  $(currentDraggable.target).removeClass("active");
  currentDraggable = this;
  $(this.target).addClass("active");
}

You can also get the element from outside of the createDraggable function by accessing that variable.

var element = $(currentDraggable.target);

And if you don't want the draggable to change the z-index, add this to the config. You may need to reorder some things though.

var draggable = new Draggable(page, {
  zIndexBoost: false,
  ...
});

.

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