关于GWT ScrollPanel的问题。如何知道在GWT中显示哪个元素ScrollPanel
有什么方法可以确定哪个子元素在ScrollPanel中显示?
(当然,ScrollPanel包含DecoratorPanel有HTML对象)
关于GWT ScrollPanel的问题。如何知道在GWT中显示哪个元素ScrollPanel
有什么方法可以确定哪个子元素在ScrollPanel中显示?
(当然,ScrollPanel包含DecoratorPanel有HTML对象)
AFAIK没有内置的功能,这样做,而不是在DOM也不在GWT。
如果你有固定高度的元素,你可以尝试计算是否显示某些元素:Check if element is visible after scrolling
这里的GWT方法,没有工作(从jQuery解决上述建议被翻译)。
/**
* @param widget the widget to check
* @return true if the widget is in the visible part of the page
*/
private boolean isScrolledIntoView(Widget widget) {
if (widget != null) {
int docViewTop = Window.getScrollTop();
int docViewBottom = docViewTop + Window.getClientHeight();
int elemTop = widget.getAbsoluteTop();
int elemBottom = elemTop + widget.getOffsetHeight();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
return false;
}
如果你想检查一个小部件是一个滚动面板可见,你可以用这种方式(类似马西的解决方案)做到这一点:我以这种方式使用此方法
/**
* @param widget the widget to check
* @return true if the widget is in the visible part of the scroll panel
*/
private boolean isVisibleInScrollPanel(Widget widget, ScrollPanel scrollPanel) {
if (widget != null) {
int containerTop = scrollPanel.getAbsoluteTop();
int containerBottom = containerTop + scrollPanel.getOffsetHeight();
int widgetTop = widget.getAbsoluteTop();
int widgetBottom = widgetTop + widget.getOffsetHeight();
return ((widgetBottom <= containerBottom) && (widgetTop >= containerTop));
}
return false;
}
:
// When the selected widget is invisible, then we ensure it to be visible
if (!isVisibleInScrollPanel(widget, scrollPanel)) {
scrollPanel.ensureVisible(widget);
}
好的。我发现类似的使用jQuery的答案。正如你所提到的,我无法在GWT中找到任何解决方案。 – ljh131
尝试在GWT中实现该逻辑。 jQuery仅用于选择正确的元素。 –