开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜