问题
When 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!
回答1:
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');
来源:https://stackoverflow.com/questions/3296182/jqueryui-draggable-constrain-draggability-to-a-single-axis