gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 15:29:49 24 4
gpt4 key购买 nike

我希望 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com