GWT - RichTextArea - ScrollTo
If I have an RichTextArea like this :
RichTextArea rta = new RichTextArea();
rta.setHTML("<p id=\"foo\">Foo</p>....<p id=\"bar\">Bar</p>");
If I extend the RichTextArea class, how would be the proper way (cross-browser wise) to write a scrollTo() method?
Ex:
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);
}
}-*/; ...
}
This seems to work in some browsers, but I don't have all of them to test, so inputs are welcome!
Thanks!
http://code.google.com/p/doctype/wiki/WindowScrollMethod - seems to be ok across browsers. http://code.google.com/p/doctype/wiki/ArticleOffsetLeftAndFriends - seems to be inconsistent.
精彩评论