从父元素拖动子元素

dragging child element from parent element

本文关键字:元素 拖动      更新时间:2023-09-26

是否可以在没有父元素溢出的情况下从父元素拖动子元素?,就像我想从父元素创建一个拖放事件,但它一直溢出,如果不可能的话? 我还能做什么?

当前示例代码:

 <div id="parent">
   <div id = "child">Drag me out from parent!</div>
 </div>

 <script>
  $("#child").draggable();
 </script>

我尝试了不同的修订,但它效果不佳,我很期待,谢谢!

也许你可以创建自己的可拖动

$('#child').on('mousedown',function(){
    $('child').css('position','fixed');
    var evt=setInterval(followMouse, 50);
    $('child').on('mouseup',function(){
        clearInterval(evt);
        $('child').off('mouseup');
    });
});
function followMouse(){
    // mousePosX & Y must be a string ex: 345px
    $('child').css('left',mousePosX
    'top',mousePosY
    );
}