我希望用户从另一个页面(即/
(转到主页,并向下滚动到该部分。这里有一个不起作用的HTML代码:
<!DOCTYPE html>
<html>
<body>
<a href="/#section-1">Section 1</a>
<div id="section-1"></div>
</body>
</html>
如果它是index.html
(即<a href="index.html#section-1">Section 1</a>
(,它会起作用,但它不只是在/
上起作用。
您可以将一些参数传递到URL?section=section1
。当安装/
组件时,检查是否存在参数,以编程方式滚动到部分:https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo