[英]Drag item outside the scrollable div with jQuery draggable
So I want to have a scrollable div with some items inside, but when I try to drag items outside it, overflow-y: scroll forces them to stay inside, and makes an unwanted horizontal scroll as well... Is there a way around it? 因此,我想创建一个可滚动的div,其中包含一些项目,但是当我尝试将其拖动到其外部时,溢出-y:滚动会迫使它们留在内部,并且还会进行不必要的水平滚动...是否有解决方法它? Here's the pen to illustrate: https://codepen.io/anon/pen/MOgqQq
这是用来说明的笔: https : //codepen.io/anon/pen/MOgqQq
.container {
width: 300px;
height: 200px;
background-color: red;
overflow-y: scroll;
}
<div class="container">
<div class="item">Drag me</div>
</div>
$(".item").draggable();
$(".container").droppable(); $(".item").draggable();
.container { width: 300px; height: 200px; background-color: red; overflow-y: scroll; } .item{ position: absolute; z-index: 1; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <!-- Also include jQueryUI --> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> <div class="container"> <div class="item">Drag me</div> </div>
u can drag outside by removing Overflow 您可以通过删除溢出将其拖到外面
$(".item").draggable();
#item {position:absolute;} .container { position:absolute; width: 300px; height: 200px; background-color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <div class="container"> <div class="item">Drag me</div> </div>
Otherwise if u want to keep overflow , you use the following method 否则,如果您想保持溢出,请使用以下方法
$(".item").draggable();
#item {position:absolute;} .container { position:absolute; width: 300px; height: 200px; background-color: red; overflow-y: scroll; }
<script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <div class="container"> </div> <div class="item">Drag me</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.