我想在固定的父级中有一个受约束的可拖动对象。 当我向下滚动时,containmet 区域与 body 一起移动,而不是与固定的 child 一起移动。有办法避免这种情况吗?
HTML:
<div id="o">
<div id="draggable">
<p>drag me</p>
</div>
</div>
JS:
$( "#draggable" ).draggable(
{ containment: [ 0 ,0, 200, 200],
scroll: false }
);
CSS:
#o {
position: fixed;
}
body {
height:1000px;
}
最佳答案
在#o
上尝试position: absolute
。 position: fixed
将固定 div 在视口(viewport)中的位置,position: absolute
将相对于最近的相对定位的父级固定 div。
编辑:
你有错误的包含值,像这样设置它被它的父级包含
$( '#draggable' ).draggable({
containment: 'parent',
scroll: false
});
关于javascript - jQuery UI Draggable,在固定父级中具有自定义包含,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24020718/