gwt锚标签不锚定 [英] gwt anchor tag not anchoring

查看:105
本文介绍了gwt锚标签不锚定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览器为什么不滚动到锚点?

url: http:// localhost:8080 / index.html#myAnchor3

Why does the browser not scroll to the anchor?
url:http://localhost:8080/index.html#myAnchor3

this.anchor1.setName("myAnchor1");
this.add(this.anchor1);
this.anchor2.setName("myAnchor2");
this.add(this.anchor2);
this.anchor3.setName("myAnchor3");
this.add(this.anchor3);

是否因为在页面加载完成后创建了锚点,所以浏览器看不到当它试图滚动到它的锚点?

Is it because the anchor is created after the page has finished loading, so the browser doesn't see the anchor when it tries to scroll to it?

推荐答案

必须重写onLoad方法,并在那里调用scrollIntoView,否则它是试图滚动到一个没有添加到DOM的对象。

Had to override the onLoad method, and call scrollIntoView there, otherwise it was trying to scroll to an object that wasn't added to the DOM yet.

public class Foo extends Widget
{
  Foo(){
  }

  @Override
  protected void onLoad(){
    super.onLoad();
    getElement().scrollIntoView();
  }
}

这篇关于gwt锚标签不锚定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆