-
Notifications
You must be signed in to change notification settings - Fork 387
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
Method to update position #147
Comments
You can set position with // jQuery
$draggable.css({
left: 200,
top: 100
});
// vanilla JS
dragElem.style.left = '200px';
dragElem.style.top = '100px'; |
The problem is Dragabilly.position becomes out of sync |
You have to both set the CSS position and manually update the draggable. This worked for me: draggable.position.x = newPosition;
draggableEl.style.left = newPosition + 'px'; That being said, the fact that you have to do what feels like reaching into the Draggable internals to do this (and seems pretty fragile) makes me think a method to do this should be built in. |
@cmalven ;) So this issue is a proposal for an abstraction which allows you to update both at once. Either with setters: draggable.position = {x, y}
// or
draggable.position.x = x
draggable.position.y = y Or with a method draggable.setPosition(x, y) Or both |
How about: // add this code
Draggabilly.prototype.setPosition = function( x, y ) {
this.position.x = x;
this.position.y = y;
this.setLeftTop();
};
// then you can use setPosition method
draggie.setPosition( 200, 100 ) See demo http://codepen.io/desandro/pen/qRQYYB Add a 👍 reaction if you would like to see this feature added to Draggabilly. |
Works fine! Thank you! 👍 |
🎉 Draggabilly v2.2.0 has been released new Please update! Closing this feature request as resolved. Please open a new issue if you run into trouble with |
Would be useful to have a method to set the position programatically.
Related to #146
The text was updated successfully, but these errors were encountered: