jQueryUI Draggable: Constrain draggability to a single axis?
Wh开发者_运维知识库en dragging an object, the user can drag in the x and y axes. I want to constrain the draggability to only the x-axis. How should I go about doing this?
Thank you!
Check out the axis option:
"Constrains dragging to either the horizontal (x) or vertical (y) axis. Possible values: 'x', 'y'."
Examples:
// Initialize a draggable with the axis option specified.
$( ".selector" ).draggable({ axis: 'x' });
// Get the axis option, after initialization.
var axis = $('.selector').draggable('option', 'axis');
// Set the axis option, after initialization.
$('.selector').draggable('option', 'axis', 'x');
精彩评论