2011-08-29 35 views

回答

0

AFAIK没有内置的功能,这样做,而不是在DOM也不在GWT。

如果你有固定高度的元素,你可以尝试计算是否显示某些元素:Check if element is visible after scrolling

+0

好的。我发现类似的使用jQuery的答案。正如你所提到的,我无法在GWT中找到任何解决方案。 – ljh131

+0

尝试在GWT中实现该逻辑。 jQuery仅用于选择正确的元素。 –

1

这里的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; 
} 
0

如果你想检查一个小部件是一个滚动面板可见,你可以用这种方式(类似马西的解决方案)做到这一点:我以这种方式使用此方法

/** 
    * @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); 
} 
相关问题