admin管理员组

文章数量:1278653

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!

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!

Share Improve this question edited Nov 8, 2014 at 4:49 rgajrawala 2,1881 gold badge24 silver badges38 bronze badges asked Jul 21, 2010 at 3:52 milanmilan 1431 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 12

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');

本文标签: javascriptjQueryUI Draggable Constrain draggability to a single axisStack Overflow