jQueryUI Draggable: Constrain draggability to a single axis?

牧云@^-^@ 提交于 2019-12-12 18:27:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!