gwt 锚标记未锚定
为什么浏览器不滚动到锚点?
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);
是否因为锚点是在页面加载完成后创建的,所以浏览器在尝试滚动到该锚点时看不到该锚点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
是的,你是对的,你的锚点是在页面加载后创建/插入的,所以......
Try this:
And yes, you are right, your anchor was created/inserted after the page load, so well.....
您可以尝试使用 Element.scrollIntoView(),它不仅会滚动窗口,还会滚动 DOM 层次结构中保存元素的任何可滚动容器。
You could try using Element.scrollIntoView(), which not only will scroll the window, but any scrollable container in the DOM hierarchy that holds the element.
必须重写 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.