2011-06-14 55 views

回答

0

不幸的是,当滚动条添加到元素或从元素中移除时不会触发事件。然而,要推出自己的产品并不难:

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); 
    } 
}