滚动时有粘性的部分,但被下面的部分覆盖
sticky sections while scrolling, but overlayed by the one below
我想创建一个登录页。滚动时,每个部分都应具有粘性。当下一个部分也应该是粘性的,但在其父部分之上。
我发现了大量的jquery插件,它们使内容具有粘性(例如fixTo)。这里的问题是,第一部分总是在顶部(无论我给标签什么z索引)。但我希望第一节在第二节之后——希望你知道我的意思。。。
是否为两个div标记都设置了z索引?
css
div1
{
position:fixed;
top:0px;
right:0px;
width:100px;
z-index:1000;
}
div2
{
position:fixed;
top:0px;
right:0px;
width:100px;
z-index:1001;
}
经过测试,第二个div在第一个div之上。
好的,感谢skibbi_bizzle的提示。解决方案是从最低的开始,给所有部分都加上负锌指数。这是代码:
HTML:
<article id="main">
<section class="wrapper" name="top" id="section-0">
<h2>Top section</h2>
<p>section content</p>
</section>
<section class="wrapper style1" name="section-1" id="section-1">
<h2>First section</h2>
<p>section content</p>
</section>
<section class="wrapper style2" name="section-2" id="section-2">
<h2>Second section</h2>
<p>section content</p>
</section>
<section class="wrapper style3" name="section-3" id="section-3">
<h2>Third section</h2>
<p>section content</p>
</section>
<section class="wrapper style4" name="section-4" id="section-4">
<h2>Fourth section</h2>
<p>section content</p>
</section>
</article>
CSS:
#main {
margin-top: 70px;
}
/* Wrapper */
.wrapper {
padding: 5em;
color: inherit;
}
.wrapper.style1 {
background: #aaa;
}
.wrapper.style2 {
background: #bbb;
}
.wrapper.style3 {
background: ccc;
}
.wrapper.style4 {
background: #ddd;
}
section {
width: 100%;
}
#section-0 {
z-index: -10;
}
#section-1 {
z-index: -9;
}
#section-2 {
z-index: -8;
}
#section-3 {
z-index: -7;
}
#section-4 {
z-index: -6;
}
JS:
$(document).ready(function () {
$("#section-0").fixTo("#main");
$("#section-1").fixTo("#main");
$("#section-2").fixTo("#main");
$("#section-3").fixTo("#main");
$("#section-5").fixTo("#main");
});
相关文章:
- 只覆盖箭头键滚动事件
- 强制滚动条覆盖页面内容
- 阻止在单击和关闭覆盖菜单css时滚动正文
- 摩尔工具覆盖窗口滚动
- 向下滚动时覆盖页面的第一个元素或块
- 如何在滚动/调整大小时保持背景图像覆盖屏幕
- 老.在IE和Firefox上覆盖滚动地图
- 如何在花式框覆盖层内滚动
- 将滚动区域的顶部与由 CSS 修复的覆盖元素分开
- 当用户使用鼠标滚动或键盘时,覆盖Fullpage.js中的自动滚动
- 滚动时有粘性的部分,但被下面的部分覆盖
- 如何删除覆盖图像查看器的溢出(滚动条)
- 移动设备上没有滚动体的全屏覆盖(jquery mobile)
- 如何制作一个有粘性的边栏'或者当你滚动到页脚时移动,这样它就不会被它覆盖
- Jquery字幕覆盖滚动时的阴影
- 带滚动的Div覆盖另一个带滚动的Div
- Jquery旋转木马为一个引导网站覆盖我的页面滚动
- 禁用滚动覆盖像Facebook一样活跃
- 当覆盖的输入框聚焦时,如何向下滚动页面
- 仅滚动到锚点/覆盖滚动