2011-08-29 5 views

答えて

0

ないDOMでもGWTで、そうする組み込みの機能はありません私の知る限り。

あなたが特定の要素が示されている場合を計算しようとする可能性があり、高さの要素を固定している場合:Check if element is visible after scrolling

+0

いいえ。私はjqueryを使って同様の答えを見つけました。あなたが言及したように、私はGWTの任意の解決策を見つけることができません。 – ljh131

+0

GWTでそのロジックを実装しようとします。 jQueryは、適切な要素を選択するためにのみ使用されていました。 –

1

ここで(それは上記の提案はJQuery溶液から翻訳された)仕事をしてGWTの方法があります。

/** 
* @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); 
} 
関連する問題