gpt4 book ai didi

jquery - Parallax Scroll - 滚动到指定的 div

转载 作者:行者123 更新时间:2023-11-28 15:56:48 26 4
gpt4 key购买 nike

我已经使用 css 设置了视差效果:JS Fiddle

代码:

body {
margin: 0px;
}
header {
height: 218px;
background: blue;
}
#fold {
background: red;
height: 100vh;
width: 100%;
position: fixed;
}
main {
background: green;
position: relative;
top: 100vh;
height: 1000px;
}
<div id="fold">
<header>header</header>
fold content
</div>
<main>main content here</main>

目前,'main' div 滚动到 body 的顶部,但是有什么方法可以让它在碰到 'header' 标签时停止吗?

我希望这是有道理的。感谢阅读,感谢您的建议。

最佳答案

你的意思是这样的吗?

body {
margin: 0;
}
#fold,
header {
width: 100%;
position: fixed;
}
header {
height: 218px;
background: #00f;
top: 0;
left: 0;
z-index: 1;
}
#fold {
background: red;
height: calc(100vh - 218px);
top: 218px;
}
main {
background: green;
position: relative;
top: 100vh;
height: 1000px;
}
<header>header</header>
<div id="fold">fold content</div>
<main>main content here</main>

我将页眉移到了折叠之外,并给了它更高的 z-index。

编辑

已更新以符合条件

body {
margin: 0px;
}
header {
height: 218px;
background: blue;
}
#fold {
background: red;
height: 100vh;
width: 100%;
position: fixed;
}
main {
background: green;
position: relative;
top: 100vh;
height: calc(100vh - 218px);
}
<div id="fold">
<header>header</header>
fold content
</div>
<main>main content here</main>

我已将 main 的高度设为页面高度减去页眉高度。使用 calc

关于jquery - Parallax Scroll - 滚动到指定的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40974691/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com