1

如果我有这样的 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);
       }
   }-*/;       ...
}

这似乎在某些浏览器中有效,但我没有要测试所有浏览器,所以欢迎输入!

谢谢!

4

1 回答 1

1

http://code.google.com/p/doctype/wiki/WindowScrollMethod - 跨浏览器似乎没问题。 http://code.google.com/p/doctype/wiki/ArticleOffsetLeftAndFriends - 似乎不一致。

于 2010-06-02T14:06:03.977 回答