我正在创建一个应用程序,用户可以将图像拖放到div上。但是图像很大,因此可放置的div可以位于页面的底部。因此,我需要一种功能,当用户拖动图像并尝试拖动到页面底部以进入可放置的div时,页面应滚动。
这是我的可拖动代码
$(".drag-img").draggable({
cursor: "move",
scroll: true,
revert: "invalid" ,
helper: function(){
$copy = $(this).clone();
return $copy;
},
appendTo: 'body',
scroll: false
});
Jquery UI有选项' scroll':true,但它不能使用clone()帮助器。你有什么建议或者我错过了什么吗?
答案 0 :(得分:1)
尝试使用div位置包裹溢出div:position; relative;并添加位置:相对;你的溢出div
<div style="position: relative;">
<div style="position:relative; background-color: red; width: 500px; height: 100px; overflow: auto;">
<table id="nfTable" class="treeTable">
<tr><td><span class="parent initialized expanded">drop here</span></td></tr>
<tr><td><span class="draggable">drag me</span></td></tr>
<tr><td><span class="draggable">drag me</span></td></tr>
<tr><td><span class="draggable">drag me</span></td></tr>
<tr><td><span class="droppable">drop here</span></td></tr>
<tr><td><span class="droppable">drop here</span></td></tr>
<tr><td><span class="draggable">drag me</span></td></tr>
<tr><td><span class="draggable">drag me</span></td></tr>
<tr><td><span class="draggable">drag me</span></td></tr>
<tr><td><span class="draggable">drag me</span></td></tr>
<tr><td><span class="droppable">drop here</span></td></tr>
<tr><td><span class="droppable">drop here</span></td></tr>
<tr><td><span class="droppable">drop here</span></td></tr>
<tr><td><span class="droppable">drop here</span></td></tr>
</table>
</div>
答案 1 :(得分:0)