GWT ScrollPanelに関する質問です。どの要素がGWT ScrollPanelで表示されているかを知る方法
どの子要素がScrollPanelに表示されているかを判断する方法はありますか?
(もちろん、ScrollPanelは、HTMLオブジェクトを持っているDecoratorPanelが含まれています)
GWT ScrollPanelに関する質問です。どの要素がGWT ScrollPanelで表示されているかを知る方法
どの子要素がScrollPanelに表示されているかを判断する方法はありますか?
(もちろん、ScrollPanelは、HTMLオブジェクトを持っているDecoratorPanelが含まれています)
ないDOMでもGWTで、そうする組み込みの機能はありません私の知る限り。
あなたが特定の要素が示されている場合を計算しようとする可能性があり、高さの要素を固定している場合:Check if element is visible after scrolling
ここで(それは上記の提案は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;
}
あなたはウィジェットがスクロールパネルに表示されているかどうかを確認したい場合は、(マッシのソリューションと同様に)、このようにそれを行うことができます。
/**
* @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は、適切な要素を選択するためにのみ使用されていました。 –