JQuery Dragging Outside Parent

前端 未结 5 2086
后悔当初
后悔当初 2020-12-20 11:31

I\'m using JQuery\'s draggable(); to make li elements draggable. The only problem is when the element is dragged outside its parent, it doesn\'t show up. That is, it doesn\'

相关标签:
5条回答
  • 2020-12-20 12:06

    I landed on this page with the exact same problem, and Brendan's answer got me close. Setting the appendTo option didn't help, but I was able to resolve my issue by adding overflow: visible to the parent of my draggable element. Turns out I was sloppily inheriting hidden from somewhere up the chain.

    Side note, it looks like this works because jQuery UI moves the draggable element by dynamically setting positioning relative to the parent - this was new intel for me!

    0 讨论(0)
  • 2020-12-20 12:10

    I had also the same problem.
    You can use this option

    containment: $('#divmain')
    helper: 'clone'

    respectively for
    - define limit area for dropping action
    - for shows visible dragged object also outside div parent but inside #divmain

    example

    <div id="divmain">
      <div id="divparentdraggable">
        <div id="divdraggable"></div>
      </div>
      <div id="divparentdroppable">
        <div id="divdroppable"></div>
      </div>
    </div>
    

    jquery code:

    $('divparentdraggable').draggable({ 
    ...
    containment: $('#divmain'),
    helper: 'clone',
    ...
    });
    

    I hope this help someone.

    0 讨论(0)
  • 2020-12-20 12:18

    I had a similar issue and resolved it by setting the option:

    appendTo: 'body'
    

    The only side effect to this is if you have styles applied to the item based on it's parent container, those styles won't be present on the helper.

    0 讨论(0)
  • 2020-12-20 12:20

    This looks like a css issue. Try turning off the revert so it stays put when you drag it to where it is half visible. Then play with the z-index etc in Firebug and see if you can get it showing. It might be a css issue with one of the parent ul or div's with 'overflow: hidden'.

    0 讨论(0)
  • 2020-12-20 12:22

    Looks like a combination of some of the above did it for me.

    Set appendTo: 'body' and helper: 'clone'. This way a new DOM-Object will be created as child of the body which will be visible everywhere. This way you can drag (and drop) it everywhere you like.

    0 讨论(0)
提交回复
热议问题