gpt4 book ai didi

javascript - 拖放不适用于缩放

转载 作者:行者123 更新时间:2023-11-28 07:11:29 26 4
gpt4 key购买 nike

我的应用程序具有拖放功能。但在缩放窗口时,拖放操作无法正常工作。这是代码。

<div class="scaled">
<div class="draggable" id="draggable"></div>
<div class="droppable" id="droppable"></div>
</div>

CSS代码

.draggable {
height: 50px;
width:50px;
background-color: yellow;
}

.droppable {
height: 50px;
width:50px;
border: 1px solid;
margin-top: 50px;
}
.scaled {
-ms-transform: scale(0.5,0.5); /* IE 9 */
-webkit-transform: scale(0.5,0.5); /* Safari */
transform: scale(0.5,0.5);
}

Jquery代码

$( "#draggable" ).draggable();
$( "#droppable" ).droppable({
drop: function( event, ui ) {
alert()
}
});

JsFiddle

最佳答案

您可以更改拖动事件中拖放的位置。

代码基于Drag n Drop not working proper on scaling the container

var zoomScale = 0.5
$(".draggable").draggable({
drag: function(event, ui) {
var changeLeft = ui.position.left - ui.originalPosition.left; // find change in left
var newLeft = ui.originalPosition.left + changeLeft / zoomScale; // adjust new left by our zoomScale

var changeTop = ui.position.top - ui.originalPosition.top; // find change in top
var newTop = ui.originalPosition.top + changeTop / zoomScale; // adjust new top by our zoomScale

ui.position.left = newLeft;
ui.position.top = newTop;
}
});

关于javascript - 拖放不适用于缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31264604/

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