2 回答
TA贡献1859条经验 获得超6个赞
您的链接和内容位于不同的 PHP 文件中并不重要,因为您链接到 URL,并且您仍然可以使用锚点将它们链接在一起,只要您可以为它们分配通用 ID:https: //developer.mozilla.org/en -US/docs/Web/HTML/Element/a#Linking_to_an_element_on_the_same_page
您还可以使用 CSS 属性scroll-behavior: smooth;
以获得更好看的滚动效果(或使用 JavaScript执行相同操作)
TA贡献1799条经验 获得超9个赞
您只需在 JavaScript 中调用一个函数即可:
<!-- JavaScript part: -->
<script type="text/javascript">
function scrollTo(id){
var element = document.getElementById(id)
// For scrolling to the top of the container:
element.scrollIntoView(True)
// Alternatively, for scrolling to the bottom of the container:
element.scrollIntoView(False)
}
</script>
<!-- Your container you want to scroll to: -->
<div id="container1">
<!-- Content of container here -->
</div>
<!-- Link for scrolling to the container, can also be included with include from php like you do it in your navbar: -->
<a href="javascript: scrollTo('container1')">
Go to container1
</a>
我希望它对你有用。
- 2 回答
- 0 关注
- 104 浏览
添加回答
举报