2011-08-29 38 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); 
} 
相關問題