首页 > 其他 > 详细

滚动视差

时间:2020-05-27 20:13:02      阅读:72      评论:0      收藏:0      [点我收藏+]

先看一下实现的效果:

技术分享图片

 

以上通过滚动,图片随之滚动

看起来蜜汁酷炫

实现原理就是:

  滚动视差,是指让多层背景以不同的速度移动,形成立体的运动效果,带来非常出色的视觉体验。

 

使用技术很简单,只需要css属性: background-attachment: fixed; 无需任何js复杂代码

代码如下:

<template>
  <div class="rollingParallax_container">
    <div class="gImg gImg1" :style="{‘height‘:currentHeight + ‘px‘}"></div>
    <div class="gImg gImg2" :style="{‘height‘:currentHeight + ‘px‘}"></div>
    <div class="gImg gImg3" :style="{‘height‘:currentHeight + ‘px‘}"></div>
  </div>
</template>
<script>
export default {
  name: "rollingParallax",
  data() {
    return {
      currentHeight: 0
    };
  },
  mounted() {
    this.currentHeight = document.body.clientHeight
    console.log(this.currentHeight);
    
  },
  methods: {}
};
</script>

<style  lang="less" scoped>
@white: #f4f4f4;
.rollingParallax_container {
  width: 100%;
  height: 100%;

  .gImg {
    background-attachment: fixed;
    background-size: cover;
    background-position: center center;
    width: 100%;
  }

  .gImg1 {
    background-image: url(‘./img/img1.png‘);
  }

  .gImg2 {
    background-image: url(‘./img/img2.png‘);
  }

  .gImg3 {
    background-image: url(‘./img/img3.png‘);
  }
}
</style>

 

滚动视差

原文:https://www.cnblogs.com/huangaiya/p/12976043.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!