gpt4 book ai didi

javascript - 拖动完div后找到左上角的位置

转载 作者:行者123 更新时间:2023-11-28 12:43:27 24 4
gpt4 key购买 nike

我有 div 容器和内部几个 div 以及类演示,例如

<div id='container' style='width:500px;height:500px;'>
<div class='demo' style='width:100px;height:100px;'></div>
<div class='demo' style='width:100px;height:100px;'></div>
<div class='demo' style='width:100px;height:100px;'></div>

</div>

并在 jquery 中准备好函数

$(function(){
$('.demo').draggable()
.resizable({
stop:function(event,ui){}
alert(ui.size.width+' '+ui.size.height);
})

});

当我使用 class='demo' inside 父 div id="container"完成拖动 div 时,如何获取左上角的位置(相对于父 div id=container)?

最佳答案

您需要使用stopposition方法

$(function(){
$('.demo').draggable({
stop: function(event, ui) {
alert('Left:' + $(this).position().left + ' Top:' + $(this).position().left);
}
}).resizable({
stop:function(event,ui){}
})
});

关于javascript - 拖动完div后找到左上角的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10531099/

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