1
我有一个GWT ScrollPanel
其overflow-y
设置为auto
。当面板的滚动条出现或消失时是否触发了一个事件?如何在滚动条出现时捕获事件?
我有一个GWT ScrollPanel
其overflow-y
设置为auto
。当面板的滚动条出现或消失时是否触发了一个事件?如何在滚动条出现时捕获事件?
不幸的是,当滚动条添加到元素或从元素中移除时不会触发事件。然而,要推出自己的产品并不难:
public class MyScrollPanel extends ScrollPanel {
boolean horizontal = false;
boolean vertical = false;
public native int getScrollHeight() /*-{
return [email protected]::getElement()().scrollHeight;
}-*/;
public native int getScrollWidth() /*-{
return [email protected]::getElement()().scrollWidth;
}-*/;
private boolean hasHorizontalScrollbar() {
return getElement().getClientWidth() < getScrollWidth();
}
private boolean hasVerticalScrollbar() {
return getElement().getClientHeight() < getScrollHeight();
}
public void onLoad() {
new Timer() {
@Override
public void run() {
boolean scrollersChanged = false;
if (hasHorizontalScrollbar() != horizontal) {
horizontal = !horizontal;
scrollersChanged = true;
}
if (hasVerticalScrollbar() != vertical) {
vertical = !vertical;
scrollersChanged = true;
}
if (scrollersChanged) {
// Fire event or call onResize()
}
}
}.scheduleRepeating(500);
}
}