我的頁面有一些部分的高度為 100vh 和一個較小的頁腳:
<!DOCTYPE html>
<html>
<head>
<title>Scroll Snap Y</title>
<style>
body {
margin: 0;
font-family: sans-serif;
font-size: 40px;
}
main {
scroll-snap-type: y mandatory;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: scroll;
/* For old browsers */
-webkit-scroll-snap-type: y mandatory;
-ms-scroll-snap-type: y mandatory;
scroll-snap-type-y: mandatory;
scroll-snap-points-y: repeat(100%);
}
section,
footer {
display: grid;
align-items: center;
justify-content: center;
scroll-snap-align: start;
}
section {
height: 100vh;
}
section:nth-child(1) {
background-color: #f00;
}
section:nth-child(2) {
background-color: #0f0;
}
footer {
background-color: #0ff;
height: 25vh;
}
</style>
</head>
<body>
<main>
<section>1</section>
<section>2</section>
<footer>
<a href="https://stackoverflow.com/" target="_blank">Stack Overflow</a>
</footer>
</main>
</body>
</html>
它在 Chrome 和 Safari 中非常完美,我滾動到頁腳并按預期點擊鏈接:
Chrome 中的視頻螢屏截圖
但是在 Firefox 中,當我點擊頁腳中的任意位置時,頁面會滾動到上一部分(圖片上的綠色部分),從而無法點擊頁腳中的鏈接,這是不可能的,因為頁面會系統地滾動到上一節:
Chrome 中的視頻螢屏截圖
如果頁腳的高度為 100vh,則頁面在 Firefox 中的行為很好,但我想要一個小的頁腳,我不想要一個高度為 100vh 的頁腳。
你有什么想法可以讓我點擊頁腳中的鏈接嗎?
uj5u.com熱心網友回復:
我通過設定scroll-snap-align: end;頁腳修復了這個 Firefox 的錯誤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/378382.html
