代码之家  ›  专栏  ›  技术社区  ›  Yanick Rochon

GWT-RichTextArea-滚动到

  •  1
  • Yanick Rochon  · 技术社区  · 16 年前

    如果我有这样一个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 回复  |  直到 16 年前
        1
  •  1
  •   Gipsy King    16 年前