Javascript 完成拖动div时查找左上角的位置
我有一个div容器,里面有两个div和类demoJavascript 完成拖动div时查找左上角的位置,javascript,jquery,Javascript,Jquery,我有一个div容器,里面有两个div和类demo <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' s
<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>
当我使用class='demo'insider parent div id=“container”完成拖动div时,如何获取左上角的位置(相对于父div id=container)?您可以使用.position()
获取匹配元素集中第一个元素的当前坐标
元素,相对于偏移父元素
更多信息请点击此处:
希望对您有所帮助:)您可以使用.position()
获取匹配元素集中第一个元素的当前坐标
元素,相对于偏移父元素
更多信息请点击此处:
希望对您有所帮助:)您需要使用和方法
你需要使用新的方法
也许这是对的
可能是正确的顺便说一句,给出此建议的原因是因为我注意到您正在使用jQuery。顺便说一句,给出此建议的原因是因为我注意到您正在使用jQuery。
$(function(){
$('.demo').draggable()
.resizable({
stop:function(event,ui){}
alert(ui.size.width+' '+ui.size.height);
})
});
$(function(){
$('.demo').draggable({
stop: function(event, ui) {
alert('Left:' + $(this).position().left + ' Top:' + $(this).position().left);
}
}).resizable({
stop:function(event,ui){}
})
});
var top = $('#container').css('top')
and
var left = $('#container').css('left')
$(function(){
$('.demo').draggable()
.resizable({
stop:function(event,ui){}
alert($(this).css("top")+' '+$(this).css("left"));
})
});