javascript - jQueryUI 可拖动 : Constrain draggability to a single axis?

标签 javascript jquery jquery-ui jquery-ui-draggable

拖动对象时,用户可以在 x 轴和 y 轴上拖动。我想将可拖动性限制为仅在 x 轴上。我应该怎样做呢?

谢谢!

最佳答案

查看 axis选项:

"Constrains dragging to either the horizontal (x) or vertical (y) axis. Possible values: 'x', 'y'."

示例:

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

关于javascript - jQueryUI 可拖动 : Constrain draggability to a single axis?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3296182/

相关文章:

javascript - 将简单的 ajax 调用转换为使用 promise jQuery/AngularJS

javascript - jQuery对话框定位根据窗口大小自动定位

jquery - 在 html 表中搜索

javascript - Node.js 引用错误 : Product is not defined

javascript - 在新选项卡中渲染静态内容(express、ejs)

javascript - 如何在html5中制作数据列表显示选项

jquery 剪贴板插件和 Bootstrap 3 工具提示

javascript - 使用不同版本的 jQuery

JavaScript UI、requirejs 和无样式内容的 Flash

Javascript:将标记添加到自定义 esri web map