2017-06-04 46 views
0

我在一個「div」中顯示了4個不同的表格,該表格顯示鏈接列表,即顯示的表格根據列表中的哪個鏈接被點擊而改變。禁用頁面滾動爲「href」

當用戶點擊某個鏈接時,頁面會自動向下滾動到「div」的頂部。我想禁用此頁面移動,有沒有辦法做到這一點?

基本上,我希望用戶能夠選擇他們想要查看的表格,但不希望頁面自動滾動到「div」的頂部。

<ul style="list-style-type: none; margin: 0; padding: 0; overflow: hidden;"> 
<li style="list-style-type: none; float: left;"><a style="color: white; font-size: 100%;" href="#MB"><strong>ONE</strong></a></li> 
<li style="list-style-type: none; float: left;"><a style="color: white; font-size: 100%;" href="#DS"><strong>TWO</strong></a></li> 
<li style="list-style-type: none; float: left;"><a style="color: white; font-size: 100%;" href="#AF"><strong>THREE</strong></a></li> 
<li style="list-style-type: none; float: left;"><a style="color: white; font-size: 100%;" href="#DT" ><strong>FOUR</strong></a></li> 

<div style="width: 100%; float: right; overflow: hidden;"> 
<div style="white-space: nowrap; width: 400%;"> 
<div id="MB" style="vertical-align:top;display: inline-block; width: 25%;">[table id=28/]</div> 
<div id="DS" style="vertical-align:top;display: inline-block; width: 25%;">[table id=29/]</div> 
<div id="AF" style="vertical-align:top;display: inline-block; width: 25%;">[table id=35/]</div> 
<div id="DT" style="vertical-align:top;display: inline-block; width: 25%;">[table id=36/]</div> 
</div> 
</div> 

回答

0

這裏最簡單的方法可能只是使用不同的ID div

您可以使用Javascript禁用或覆蓋瀏覽器的默認滾動行爲。

+0

你能提供一個關於我可以在哪裏獲得相關信息的建議嗎? – Morts81

+0

https://stackoverflow.com/questions/3659072/how-to-disable-anchor-jump-when-loading-a-page –

+0

謝謝凱瑟琳。我對JavaScript沒有任何經驗,我可以將代碼添加到與我的HTML代碼相同的代碼片段文件中嗎?有什麼特別的使用JavaScript的? – Morts81

相關問題