css实现视差滚动效果

css实现视差滚动效果

实现该效果其实非常简单,就是background-attachment:fixed
background-attachment有三个属性值
在这里插入图片描述
下面是效果:
在这里插入图片描述

在这里插入图片描述

 <body>
    <div class="box">
      <div class="flowImage fixed-bg bg1">
        <p>aaa</p>
      </div>
      <div class="flowImage fixed-bg bg2">
        <p>bbb</p>
      </div>
      <div class="flowImage fixed-bg bg3">
        <p>ccc</p>
      </div>
      <div class="flowImage fixed-bg bg4">
        <p>ddd</p>
      </div>
      <div class="flowImage fixed-bg bg5">
        <p>eee</p>
      </div>
      <div class="flowImage fixed-bg bg6">
        <p>fff</p>
      </div>
    </div>
  </body>
body, html {
    height: 100%;
    margin: 0;
    padding: 0
}

.box {
    height: 100%;
}

.flowImage {
    height: 500px;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center center;
    /* 关键代码 */
   background-attachment: fixed; 
}

.flowImage>p {
    margin: 0;
    color: #fff;
    font-size: 30px;
}

.bg1 {
    background-image: url('https://img2.baidu.com/it/u=2774200779,2806926182&fm=253&fmt=auto&app=138&f=JPEG?w=468&h=312');
}

.bg2:nth-child(2) {
    background-image: url('https://img2.baidu.com/it/u=2071017917,3511466775&fm=26&fmt=auto');
}

.bg3:nth-child(3) {
    background-image: url("https://img0.baidu.com/it/u=1047766032,2215646629&fm=253&fmt=auto?w=282&h=188");
}

.bg4:nth-child(4) {
    background-image: url("https://img1.baidu.com/it/u=3634692134,880218970&fm=253&fmt=auto&app=138&f=JPEG?w=636&h=426");
}

.bg5:nth-child(5) {
    background-image: url("https://img2.baidu.com/it/u=2273407447,338628316&fm=253&fmt=auto&app=120&f=JPEG?w=980&h=631");
}

.bg6:nth-child(6) {
    background-image: url("https://img1.baidu.com/it/u=3107176190,1328093718&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=333");
}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值