GWT - RichTextArea - ScrollTo

时间:2010-06-02 10:19:50

标签: gwt scrollto

如果我有这样的RichTextArea:

RichTextArea rta = new RichTextArea();
rta.setHTML("<p id=\"foo\">Foo</p>....<p id=\"bar\">Bar</p>");

如果我扩展RichTextArea类,那么编写scrollTo()方法的方法是什么(跨浏览器方式)?

例如:

class RichTextAreaExt extends RichTextArea {
   ...
   /**
    * This method should be called only when the widget has properly been attached
    * @param id String the HTML element id within the RichTextArea to scroll to
    */
   public native void scrollToElement(String id) /*-{
       var cWin = this.@org.foo.project.client.com.text.MyTextArea::getElement()().contentWindow;
       var el = cWin.document.getElementById(id);
       if (el) {
           cWin.scrollTo(el.offsetLeft,el.offsetTop);
       }
   }-*/;       ...
}

这似乎适用于某些浏览器,但我没有全部测试,所以欢迎输入!

谢谢!

1 个答案:

答案 0 :(得分:1)