2012-03-03 66 views
2

是否可以確定某個特定的小部件是否顯示在視口中?確定GWT中的視口中是否顯示小部件

我想要在我的listwidget中的最後一個小部件向用戶顯示後開始加載更多數據。我想我可以處理滾動事件,並且爲每個事件檢查是否顯示最後一個小部件,以及rpc的火情以獲取更多數據。

BR

回答

0

已從GWT Showcase's CellList sample看看ShowMorePagerPanel

您可以使用Widget的getElement()getOffsetTop()和滾動元件的getScrollTop()(相當於getVerticalScrollPosition()ScrollPanel)來計算小部件是否是當前鑑於(提防'的元素getOffsetParent()不過,您可能希望設置滾動元素的CSS positionrelative使其widget的偏移父

1

這裏的GWT方法,沒有工作(這是從jQuery的解決方案here翻譯)。

/** 
* @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; 
} 
相關問題