Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contain top-down, not bottom-up #185

Closed
zzzgit opened this issue Mar 6, 2018 · 3 comments
Closed

contain top-down, not bottom-up #185

zzzgit opened this issue Mar 6, 2018 · 3 comments
Assignees
Labels

Comments

@zzzgit
Copy link

zzzgit commented Mar 6, 2018

https://codepen.io/zzzgit/pen/wyLjYN

when the content is heigher than the container, the title will be unreachable after a dragging action.
what i want is keeping the title alway in the container to make sure i can drag it anytime
could you tell me how to modify the source code?

@desandro desandro changed the title a bug when shiz is heigher than the container contain top-down, not bottom-up Mar 9, 2018
@desandro desandro added the bug label Mar 9, 2018
@desandro
Copy link
Owner

desandro commented Mar 9, 2018

Thanks for reporting this bug. I'll add a fix for this in the next release. Until then you can fix this by adding this code:

function applyGrid( value, grid, method ) {
  method = method || 'round';
  return grid ? Math[ method ]( value / grid ) * grid : value;
}

Draggabilly.prototype.containDrag = function( axis, drag, grid ) {
  if ( !this.options.containment ) {
    return drag;
  }
  var measure = axis == 'x' ? 'width' : 'height';

  var rel = this.relativeStartPosition[ axis ];
  var min = applyGrid( -rel, grid, 'ceil' );
  var max = this.containSize[ measure ];
  max = applyGrid( max, grid, 'floor' );
  return  Math.max( min, Math.min( max, drag ) );
};

See demo https://codepen.io/desandro/pen/vREyZZ

@desandro desandro self-assigned this Mar 9, 2018
@zzzgit
Copy link
Author

zzzgit commented Mar 10, 2018

okay thanks
can you release a new npm package?

@desandro
Copy link
Owner

🎉 Draggabilly v2.2.0 has been released with a fix for this issue. 🎉

Please update! Closing this as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants