GWT - RichTextArea - 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 = [email protected]::getElement()().contentWindow;
var el = cWin.document.getElementById(id);
if (el) {
cWin.scrollTo(el.offsetLeft,el.offsetTop);
}
}-*/; ...
}
这似乎在某些浏览器中有效,但我没有对所有浏览器进行测试,因此欢迎输入!
谢谢!
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 = [email protected]::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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://code.google.com/p/doctype/wiki/WindowScrollMethod - 跨浏览器似乎没问题。
http://code.google.com/p/doctype/wiki/ArticleOffsetLeftAndFriends - 似乎不一致。
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.