简体   繁体   English

如何在浏览器中仅滚动顶层以覆盖底层?

[英]How to scroll only top layer to cover over bottom layer in browser?

In this example, they somehow are able to scroll the top layer in the browser to cover over the bottom layer div. 在这个例子中,他们以某种方式能够滚动浏览器中的顶层以覆盖底层div。 How can that be done with jquery/CSS? 如何用jquery / CSS完成?

www.sevenly.org www.sevenly.org

Here's an idea how you can achieve this. 这是一个如何实现这一目标的想法。 You can improve this to your needs. 您可以根据自己的需要进行改进。 The background layer is fixed as well as the <nav> -element. 修复了背景图层以及<nav> -element。 All elements have different values for z-index to make the content scroll between the background and navigation. 所有元素都具有不同的z-index值,以使内容在背景和导航之间滚动。

Demo 演示

http://jsfiddle.net/RjGsM/ http://jsfiddle.net/RjGsM/

HTML HTML

<div class="background"></div>
<nav></nav>
<div class="content"></div>

CSS CSS

div.background {
    position: fixed;
    z-index: 0;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    margin-top: 50px;
    background: red;
}

div.content {
    position: relative;
    z-index: 1;
    height: 100%;
    width: 100%;
    margin-top: 300px;
    background: blue;
}

nav {
    position: fixed;
    z-index: 2;
    top: 0;
    left: 0;
    height: 50px;
    width: 100%;
    background: black;
}

Add {position: fixed} to the "layer" (div) you don't want to be scrolled. 将{position:fixed}添加到您不想滚动的“图层”(div)。 Make sure it's z-index is lower than the divs that do scroll. 确保它的z-index低于滚动的div。

But be warned, the mobile compatibility for this isn't great :) 但请注意,移动兼容性并不是很好:)

通过在您的body元素中添加一些填充来实现此效果(sevenly.org使用600px - 大约右侧),然后将元素绝对定位在背景中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM