vue实现banner倾斜拼接切换效果

vue yekong

vue项目外包开发时,banner是类似平行四边形和梯形的方式拼接切换的,研究了几种方式,最终感觉其中一个比较合适就选择了这一种。
vue实现banner倾斜切换效果

/**
* @Author: 858834013@qq.com
* @Name: banner
* @Date: 2022-08-31
* @Desc:
*/
<template>
  <div class="centerBanner">
    <div class="centerBanner1 transition cur " :class="{active:active==0}" @click="active=0">
      <div class="centerBannerInner">
        <div class="mask"></div>
        <item v-if="active==0"></item>
      </div>
    </div>
    <div class="centerBanner2 transition cur " :class="{active:active==1}" @click="active=1">
      <div class="centerBannerInner">
        <div class="mask"></div>
        <item2 v-if="active==1"></item2>
      </div>
    </div>
    <div class="centerBanner3 transition cur" :class="{active:active==2}" @click="active=2">
      <div class="centerBannerInner">
        <div class="mask"></div>
        <item3 v-if="active==2"></item3>
      </div>
    </div>
  </div>
</template>

<script>
import item from './item'
import item2 from './item2'
import item3 from './item3'

export default {
  name: "centerBanner",
  components: {item, item2, item3},
  props: {
    id: {
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      active: 0
    }
  },
  watch: {},
  mounted() {
  },
  methods: {}
}
</script>

<style lang="scss" scoped>
.centerBanner {
  width: 100%;
  overflow: hidden;
  height: 840px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: nowrap;
  flex-direction: row;
  align-content: flex-start;
  position: relative;

  .mask {
    position: absolute;
    background: rgba(0, 0, 0, 0.3);
    top: 0;
    z-index: 8;
    width: 100%;
    height: 100%;
    left: 0;
  }

  .centerBanner1 {
    transform: skewX(-20deg);
    width: 100%;
    position: relative;
    height: 100%;
    left: 0;
    flex: 1;
    margin-left: -10%;
    margin-right: 5%;
    overflow: hidden;

    .centerBannerInner {
      position: relative;
      transform: skewX(20deg);
      background: url("../../../assets/zhongxun/banner.jpg") center center no-repeat;
      background-size: 1920px 840px;
      margin-left: -50%;
      margin-right: -50%;
      width: 200%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-wrap: nowrap;
      flex-direction: row;
      align-content: flex-start;
    }
  }

  .centerBanner2 {
    transform: skewX(-20deg);
    width: 100%;
    position: relative;
    height: 100%;
    left: 0;
    flex: 1;
    overflow: hidden;
    margin-right: -10%;
    margin-left: -10%;

    .centerBannerInner {
      position: relative;
      transform: skewX(20deg);
      background: url("../../../assets/zhongxun/banner2.jpg") center center no-repeat;
      background-size: 1920px 840px;
      margin-left: -55%;
      margin-right: -55%;
      width: 200%;
      height: 100%;
    }
  }

  .centerBanner3 {
    transform: skewX(-20deg);
    width: 100%;
    position: relative;
    height: 100%;
    left: 0;
    flex: 1;
    overflow: hidden;
    margin-right: -10%;

    .centerBannerInner {
      position: relative;
      transform: skewX(20deg);
      background: url("../../../assets/zhongxun/banner3.jpg") center center no-repeat;
      background-size: 1920px 840px;
      margin-left: -55%;
      margin-right: -55%;
      width: 200%;
      height: 100%;
    }
  }

  .active {
    flex: 4;
  }
}
</style>

喜欢