我在使用 Chrome 的外部锚链接时遇到问题。在我的网站上,单击链接时,我想从子页面导航回到主页的特定部分。我使用一个简单的#锚来实现此目标,就像过去一样……在chrome之外的所有浏览器中都可以正常工作。单击 chrome 中的链接时,我被重定向到主页的顶部。(但我可以看到 url 栏中显示的 #anchor)对于所有其他浏览器,此操作可以正常工作。这是由于chrome的错误吗?如果是这样,有人可以建议解决方法吗?这是我得到的代码。在主页上:<div id="page-anchor"></div>
在子页面上: <div id="go_back"><p ><a id="back" href="../index.html#page-anchor" target="_self">back to portfolio</a></p></div>
我有同样的问题。试试这个解决方法
var hash = window.location.hash;
if ($(hash).length) {
$('html, body').stop().animate({
scrollTop: $(hash).offset().top
}, 1000);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句