gpt4 book ai didi

angularjs - 防止$anchorScroll修改url

转载 作者:行者123 更新时间:2023-12-02 19:23:26 28 4
gpt4 key购买 nike

我正在使用$anchorScroll滚动到页面顶部,其中 html 元素具有 ID #brand

<body>
<header id="brand">
<!--Content-->
</header>
</body>

AngularJS 代码:

$location.hash("brand");
$anchorScroll();

但是,$anchorScroll运行后,页面url变为http://localhost:8080/##brand,即##brand code> 附加到原始 url 后。使用$anchorScroll时如何保留原始url?提前致谢!

最佳答案

以显式形式使用 $anchorScroll 似乎有效,至少在 html5mode 时如此。已开启。

(do not call $location.hash())
$anchorScroll('brand');

关于angularjs - 防止$anchorScroll修改url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38079284/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com