Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 完成拖动div时查找左上角的位置_Javascript_Jquery - Fatal编程技术网

Javascript 完成拖动div时查找左上角的位置

Javascript 完成拖动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容器,里面有两个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' 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"));
})

});