Drag div by handle that is not nested

后端 未结 1 1853
被撕碎了的回忆
被撕碎了的回忆 2020-12-21 11:46

In the JQueryUI draggable demo, I can see you can attach a handle to a DIV but if the handle is not nested within the parent DIV that is draggable, it doesn\'t work e.g.

相关标签:
1条回答
  • 2020-12-21 12:46

    One possible solution could be to have the handle inside, but use css to position it outside.

    Javascript:

    $("#draggable").draggable({handle:"#handle"});
    

    HTML:

     <div id="draggable">draggable
    <div id="handle">handle</div>
     </div>
    

    CSS:

    #draggable{
    display: block; 
    height: 300px; 
    width: 600px; 
    background-color: gray;
    }
    #handle{
    display: block; 
    height: 50px; 
    width: 600px; 
    background-color: green;
    position: relative;
    top: -30px;
    }
    

    Otherwise, you might have to do something similar to a multiselect draggable. How do I drag multiple elements at once with JavaScript or jQuery?

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