【发布时间】:2011-01-07 02:09:42
【问题描述】:
我在一个 div 中有许多元素(浮动 href 标记),它们的高度/宽度都设置了,并且在 CSS 中滚动设置为 overflow: auto。
这是 div 的结构:
<div id="tagFun_div_main">
<div id="tf_div_tagsReturn">
<!-- all the draggable elements go in here, the parent div scolls -->
</div>
<div id=" tf_div_tagsDrop">
<div id="tf_dropBox"></div>
</div></div>
父 div 的 'tf_div_tagsReturn' 和 'tf_div_tagsDrop' 最终将彼此相邻。
这是在使用类名“tag_cell”创建所有“可拖动”元素之后运行的 jQuery,:
$(function() {
$(".tag_cell").draggable({
revert: 'invalid',
scroll: false,
containment: '#tagFun_div_main'
});
$("#tf_dropBox").droppable({
accept: '.tag_cell',
hoverClass: 'tf_dropBox_hover',
activeClass: 'tf_dropBox_active',
drop: function(event, ui) {
GLOBAL_ary_tf_tags.push(ui.draggable.html());
tagFun_reload();
}
});
});
如上所述,可拖动元素在 div 'tf_div_tagsReturn' 内是可拖动的,但它们不会在视觉上拖动到父 div 之外。值得注意的是,如果我拖动其中一个可拖动元素,并将鼠标移到可放置的 div 上,id 为 'tf_dropBox',然后悬停类被触发,我就再也看不到可拖动元素了。
这是我第一次使用 jQuery,所以希望我只是遗漏了一些非常明显的东西。到目前为止,我一直在阅读文档和搜索论坛,但没有成功:(
更新:
非常感谢 Jabes88 提供的解决方案,使我能够实现我正在寻找的功能。这是我的 jQuery 最终的样子:
$(function() {
$(".tag_cell").draggable({
revert: 'invalid',
scroll: false,
containment: '#tagFun_div_main',
helper: 'clone',
start : function() {
this.style.display="none";
},
stop: function() {
this.style.display="";
}
});
$(".tf_dropBox").droppable({
accept: '.tag_cell',
hoverClass: 'tf_dropBox_hover',
activeClass: 'tf_dropBox_active',
drop: function(event, ui) {
GLOBAL_ary_tf_tags.push(ui.draggable.html());
tagFun_reload();
}
});
});
【问题讨论】:
-
批评:不要混用 " 和 '。坚持其中之一。Muy, muy importante tripleexclamationsign.
-
设置助手:“克隆”成功了——太棒了! - 虽然我使用 this.style.visibility='hidden' 来隐藏原件,因为弄乱显示是不好的。
标签: jquery user-interface drag-and-drop scroll