我需要知道 VerticalPanel 何时改变大小
我正在使用 gwt-dnd 在我的 GWT 程序中实现拖放功能。为了使滚动正常工作,我需要
<ScrollPanel>
<AbsolutePanel>
<VerticalPanel>
<!-- lots of draggable widgets -->
</VerticalPanel>
</AbsolutePanel>
</ScrollPanel>
手动将 AbsolutePanel 的大小设置为足够大以包含 VerticalPanel。但是,当我将小部件添加到 VerticalPanel 时,VerticalPanel.getOffsetHeight() 报告的大小不会立即更新 - 我想它必须首先由浏览器呈现。所以我无法立即更新 AbsolutePanel 的大小,最终它太小了。啊!
我的权宜之计是设置一个计时器,在 500 毫秒后调整面板大小。届时,getOffsetHeight 通常会返回更新后的值。有什么办法可以立即预览尺寸变化或者其他什么吗?或者,我可以立即强制渲染循环,以便我可以获得新的大小,而无需设置注定容易出错的计时器吗?
I'm using gwt-dnd to implement drag-and-drop functionality in my GWT program. To get scrolling to work right, I need
<ScrollPanel>
<AbsolutePanel>
<VerticalPanel>
<!-- lots of draggable widgets -->
</VerticalPanel>
</AbsolutePanel>
</ScrollPanel>
I have to manually set the size of the AbsolutePanel to be large enough to contain the VerticalPanel. When I add widgets to the VerticalPanel, though, the size reported by VerticalPanel.getOffsetHeight() isn't immediately updated - I guess it has to be rendered by the browser first. So I can't immediately update the AbsolutePanel's size, and it ends up being too small. Argh!
My stop-gap solution is to set up a timer to resize the panel 500ms later. By then, getOffsetHeight will usually be returning the updated values. Is there any way to immediately preview the size change, or anything? Or, alternatively, can I force a render loop immediately so that I can get the new size without setting up a timer that's bound to be error-prone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 DOM 操作的常见问题。 offsetHeight 在添加组件后不久才会更新。我喜欢使用递归计时器来处理这个问题,直到违反先决条件。例如,在您的情况下,有一个添加组件的函数,其定义如下:
This is a common problem with DOM manipulations. The offsetHeight doesn't update until a short time after components are added. I like to handle this using a recursive timer until a pre-condition is violated. E.g. In your case let there be a function which adds components and will be defined as below: