jquery - 在 jquery-ui 可拖动方法中使 ui.helper 的光标位置在中心

标签 jquery html css jquery-ui jquery-ui-draggable

我希望 cursor 位于 center ui.helper of draggable

我是这样做的

$(".soclass").draggable({

          cursor: "move",
          helper: 'clone',
          revert: "invalid",
          tolerance: "fit",
          start: function(event, ui){

             $(this).draggable("option", "cursorAt", {
            left: Math.floor(ui.helper.width() / 2),
            top: Math.floor(ui.helper.height() / 2)
          }); 


          }

      });

Using this i get cursor in the center only after First drop. How can I center align the cursor right from first drop.

Jsfiddle

最佳答案

您可以访问可拖动实例的 offset.click 属性,这几乎就是将光标设置为选项所做的设置选项的问题,正如您所描述的那样仅在您下次触发 start 事件时应用。但是使用该属性,您可以在当前事件上设置它。像这样:

start: function(event, ui){
    $(this).draggable('instance').offset.click = {
        left: Math.floor(ui.helper.width() / 2),
        top: Math.floor(ui.helper.height() / 2)
    }; 
}

https://jsfiddle.net/38fay00b/

关于jquery - 在 jquery-ui 可拖动方法中使 ui.helper 的光标位置在中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34827181/

相关文章:

JQuery 下拉鼠标悬停

html - 在页面上垂直和水平居中 <div> 的最佳方法?

Python selenium xpath 获取文本为空

javascript - 根据以像素为单位的字符串实际宽度对数组进行排序

javascript - 图表 js 大小和位置

html - 为属于 span 标签的不同类设置样式

javascript - 为什么期望 Flash 可用/启用是可以接受的,但 JavaScript 不是?

c# - 需要在每个浏览器中显示相同的 Div 高度

javascript - "JavaScript APIs"是什么意思?

javascript - 如何创建 Chrome 扩展程序以使用 JavaScript 隐藏或删除页面元素?