简体   繁体   English

滚动到gwt应用程序中页面的顶部

[英]Scrolling to the top of a page in a gwt application

I've got a gwt application and I want to scroll to the top of a page using this method: 我有一个gwt应用程序,我想使用此方法滚动到页面顶部:

public static native void scrollTop() /*-{
  $wnd.scroll(0, 0);
}-*/;

The method is called in the onClick-method of a TreeNodeListenerAdapter: 该方法在TreeNodeListenerAdapter的onClick方法中调用:

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 请确保您导入的是正确的软件包com.google.gwt.user.client.Window

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM