当拖动其中的项目并达到限制时展开包含 div
我的页面有几个可拖动和调整大小的项目(div)。 我执行此操作的代码如下:
part.draggable(
{
containment: 'parent',
drag: function(event, ui){
partIsDragging = true
part.prev().css('top', ui.position.top - 20 ).css('left', ui.position.left )
part.prev().show()
},
stop: function(event, ui) {
partIsDragging = false
}
}).resizable({
containment: 'parent',
handles: 'ne, se, sw, nw,n,w,e,s',
stop: function() {
}
});
这些的 html 结构如下:
<body>
<div id="wrapper">
<div class="draggableItem"></div>
<div class="draggableItem"></div>
<div class="draggableItem"></div>
<div class="draggableItem"></div>
</div>
</body>
在我的 css 文件中,我设置了主体高度:100%和包装器高度:100%。包装器的宽度始终是固定的,宽度:950px。我希望当draggableItem 到达包装器的底部时我的div 的高度会扩展。现在,当加载页面时,它的高度与分辨率允许的一样大,但如果我在包装器中有更多项目,那么一切都会变得混乱,我希望在拖动项目时以某种方式动态扩展包装器的高度。仅当我到达底部边框时才会发生这种情况。
PS:我正在使用 jQuery 和 jQuery-ui。
My page has several items (divs) that are draggable and resizable.
My code for doing this is given below:
part.draggable(
{
containment: 'parent',
drag: function(event, ui){
partIsDragging = true
part.prev().css('top', ui.position.top - 20 ).css('left', ui.position.left )
part.prev().show()
},
stop: function(event, ui) {
partIsDragging = false
}
}).resizable({
containment: 'parent',
handles: 'ne, se, sw, nw,n,w,e,s',
stop: function() {
}
});
The html structure for these is the following:
<body>
<div id="wrapper">
<div class="draggableItem"></div>
<div class="draggableItem"></div>
<div class="draggableItem"></div>
<div class="draggableItem"></div>
</div>
</body>
In my css files i have set body height: 100% and wrapper height: 100%. Width is always fixed for wrapper, width: 950px. I want my div to expand in height when the draggableItem reaches the bottom of the wrapper. Right now when the page is loaded, it has the height as big as the resolution allows it but in case I have more items in the wrapper then everything becomes cluttered and I would like when dragging an item to somehow expand the wrapper in height dynamically. This should happen only if I hit the bottom border.
PS: I am using jQuery and jQuery-ui.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也许有解决办法。首先,我在适当的情况下将
part
替换为'.draggableItem'
和this
。请告诉我这是否会以某种关键方式破坏代码。此外,我在下面的代码中删除了part.prev().css('top', ui.position.top - 20 ).css('left', ui.position.left )
。函数
adjustWrapperHeight(movingObject)
根据movingObject
的底部位置调整div#wrapper
的高度。也就是说,当movingObject
“向上推”div#wrapper
的边框时,它会调整div#wrapper
的高度。我不得不使用
可调整大小
的技巧。resized
的containment: 'parent'
(但不是draggable
)将容器设置为容器的 ORIGINAL 高度或看来是这样。这意味着当div#wrapper
的高度动态变化时,containment: 'parent'
设置的约束不会动态变化。为了解决这个问题,我删除了containment: 'parent'
以及整个containment
并确保div#wrapper
的正确包含不存在在resize
事件中损坏。请注意,您可能也应该使用div#wrapper
的左侧遏制来执行此操作。请告诉我这是否有帮助。谢谢。
I may have a solution. First off, I replaced
part
with'.draggableItem'
andthis
where appropriate. Please tell me if that breaks the code in some critical way. In addition, I removedpart.prev().css('top', ui.position.top - 20 ).css('left', ui.position.left )
in the code below.The function
adjustWrapperHeight(movingObject)
adjustsdiv#wrapper
's height depending on amovingObject
's bottom position. That is, whenmovingObject
"pushes up" againstdiv#wrapper
's borders, it adjustsdiv#wrapper
's height.I had to use a hack for
resizable
. Thecontainment: 'parent'
forresizable
(but notdraggable
) sets the containment to the container's ORIGINAL height or so it seems. That means as the height ofdiv#wrapper
dynamically changes, the constraint set bycontainment: 'parent'
does not dynamically change. To fix this, I removedcontainment: 'parent'
and indeed the entirecontainment
and ensured thatdiv#wrapper
's right containment isn't broken within theresize
event. Note that you should probably do this withdiv#wrapper
's left containment as well.Please tell me if this was helpful. Thank you.