开发者

Scrolling to the top of a page in a gwt application

开发者 https://www.devze.com 2023-01-05 20:19 出处:网络
I\'ve got a gwt application and I want to scroll to the top of a page using this method: public static开发者_开发技巧 native void scrollTop() /*-{

I've got a gwt application and I want to scroll to the top of a page using this method:

public static开发者_开发技巧 native void scrollTop() /*-{
  $wnd.scroll(0, 0);
}-*/;

The method is called in the onClick-method of a TreeNodeListenerAdapter:

new TreeNodeListenerAdapter() {
  @Override
  public void onClick(Node node, EventObject e) {
    scrollTop();
  }
}

This does not work and I don't know why. When I put an alert inside my method:

$wnd.alert("Treenode clicked");

I get to see the alert but the page is not scrolled. What am I missing here?


If you want to scroll to the top of a page just do:

Window.scrollTo (0 ,0);

Just be sure that you are importing the correct package com.google.gwt.user.client.Window

0

精彩评论

暂无评论...
验证码 换一张
取 消