重定向到新页面并滚动到该新页面上的特定div



有人知道如何重定向到新页面并滚动到该新页面上的特定div吗?目前我正在使用这个,但它只在同一页中滚动。如何使用href重定向并使其仍然有效?

<a href="javascript:void(0);"
data-target=".offer_container" class="header-nav-item"
onClick="document.getElementById('test').scrollIntoView();"
>
Link
</a>

使用锚链接。为要滚动到的元素/节设置一个id,并使用hash使用该id链接到此页面,例如。<h2 id="section_to_scroll">Title</h2>部分

链路-<a href="/new-page.html#section_to_scroll">Page</a>

更多信息-https://www.w3docs.com/snippets/html/how-to-create-an-anchor-link-to-jump-to-a-specific-part-of-a-page.html

最新更新