2 回答

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
您的鏈接和內(nèi)容位于不同的 PHP 文件中并不重要,因?yàn)槟溄拥?URL,并且您仍然可以使用錨點(diǎn)將它們鏈接在一起,只要您可以為它們分配通用 ID:https:?//developer.mozilla.org/en -US/docs/Web/HTML/Element/a#Linking_to_an_element_on_the_same_page
您還可以使用 CSS 屬性scroll-behavior: smooth;
以獲得更好看的滾動(dòng)效果(或使用 JavaScript執(zhí)行相同操作)

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個(gè)贊
您只需在 JavaScript 中調(diào)用一個(gè)函數(shù)即可:
<!-- 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>
我希望它對(duì)你有用。
- 2 回答
- 0 關(guān)注
- 128 瀏覽
添加回答
舉報(bào)