css使背景图像位置固定并滚动内容

Lea*_*ing 6 html css

我们怎么能做类似于这个例子中所做的事情http://theme.nileforest.com/html/mazel-v1.1/home-text-rotator1.html

他们正在修复背景图像和内容.我不确定他们是如何做到这一点只有css或他们使用java脚本.

我仍然想弄明白.

任何固定的示例或指针都可以很好地开始

Dmi*_*riy 8

* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}
.block-parallax-1 {
    overflow: hidden;
    position: relative;
}
.block-parallax-1 .parallax-bg {
    background-attachment: fixed;
    background-image: url('http://bygaga.com.ua/uploads/posts/1354003535_podborka_krasivih_moto_759-58.jpg');
    background-position: 0px 0px;
    background-repeat: repeat;
    height: 100%;
    position: absolute;
    width: 100%;
    min-width: 1170px;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    background-size: cover;
}
.block-parallax-1 .md-box {
    padding: 200px 0 200px;
    background: rgba(0, 0, 0, 0.75);
    position: relative;
    height: 100%;
    text-align: center;
}
.block-parallax-1 .md-box h1 {
    color: #fff;
}

.block-parallax-2 .parallax-bg { 	
	background-image: url('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ_z73DvFVC1ek9ZsGdCpvpDW_AwRqOWgG6IP2wOXrVibxz_EDV');
}



h2 {
    color: #555;
    text-align: center; 
    padding: 25px 0;
    margin: 0;
}
Run Code Online (Sandbox Code Playgroud)
<section class="block-parallax-1">
    <div class="parallax-bg"></div>
    <div class="md-box">
         <h1>background-attachment:fixed</h1>
    </div>
</section>
    
    <section style="min-height:400px;">
        <h2>background</h2>
 <p></p>
    </section>

<section class="block-parallax-1  block-parallax-2">
    <div class="parallax-bg"></div>
    <div class="md-box">
         <h1>background-attachment:fixed</h1>
    </div>
</section>
Run Code Online (Sandbox Code Playgroud)


Amm*_*CSE 7

尝试添加

#myBackgroundContainer{
    background-attachment:fixed;
}
Run Code Online (Sandbox Code Playgroud)

来自文档

background-attachment CSS属性确定图像的位置是否在视口中固定,或者与其包含的块一起滚动.

body  {
    background-image: url('https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSHC-qntWkhfC_CP9UcIle2WQItuhlbFS_AGK3WdtrAc4Pp6OIu');
    background-repeat: no-repeat;
    background-attachment: fixed;
}
#Partition{
  background:gray;
  height:200px;  
}
Run Code Online (Sandbox Code Playgroud)
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div id="Partition"></div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>

<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
<div> scroll me </div>
Run Code Online (Sandbox Code Playgroud)