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 に答える