vue高仿立体卡片效果(第一版)

16 篇文章 1 订阅
12 篇文章 0 订阅
如图所示:

请添加图片描述

代码如下:(复制另存txt,修改.html直接运行)
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>vue高仿立体卡片效果</title>
  <!-- 引入样式 -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  <style>
    .fu{
      margin: 0 auto;
      background: #eee;
      height: 50px;
      display: flex;
      position:relative;
      text-align: center;
    }
    .fu .zi{
        flex:1;
        height: 40px;
        line-height: 40px;
        background: #ddd;
        position: relative;
        bottom: 0;
        margin-top: 10px;
    }
    .fu .rightBox::after{
      content: '';
      position: absolute;
      z-index: 2;
      bottom: 0;
      right: -10px;
      height: 50px;
      width: 15px;
      background: #fff;
      box-shadow: 2px 0px 0px #aaa;
      transform: skew(10deg);
      border-radius: 0 5px 0 0;
    }
     .leftBox::before{
      content: '';
      position: absolute;
      z-index: 1;
      left: -10px;
      height: 50px;
      width: 15px;
      background: #fff;
      box-shadow: -2px 0px 0px #aaa;
      transform: skew(-10deg);
      border-radius: 5px 0 0 0;
    }
    .fu .active{
      background: #fff;
      height: 50px;
      line-height: 50px;
      bottom: 10px;
    }
  </style>
</head>
<body style="background: #eee;">
  <div id="app">
    <div class="fu">
      <span class="zi" :class="[tabIndex == 0?'rightBox active':'']" @click="clickTab(0)" >吃鸡</span>
      <span class="zi" :class="[tabIndex == 1?'active rightBox leftBox':'']" @click="clickTab(1)">王者</span>
      <span class="zi" :class="[tabIndex == 2?'leftBox active':'']" @click="clickTab(2)">LOL</span>
    </div>
    <div style="background: #fff;height: 100px;text-indent: 2em;">
        {{['P城刚枪,成为P城之王!','王者滴滴,实力带飞!','面对疾风吧!哈撒给,嘿呀给给痛'][tabIndex]}}
    </div>
  </div>
</body>

<script src="https://lib.baomitu.com/vue/2.6.14/vue.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<!-- 引入 echart -->
<script src="https://lib.baomitu.com/echarts/5.2.0/echarts.common.js"></script>

<script>
  new Vue({
    el: '#app',
    data() {
      return { 
        tabIndex:0,
      }
    },
    mounted(){

    },
    methods: {
      clickTab(val){
        this.tabIndex = val
      }
    }
  })
</script>
</html>
vue高仿立体卡片效果(第二版): vue高仿立体卡片效果(第二版)
vue高仿立体卡片效果(第三版): vue高仿立体卡片效果(第三版)
番外篇:

越来越发现管理的重要性,码农常有,而管理不常有,好的管理事半功倍。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要实现Vue卡片左右重叠并且左右滑动,可以使用CSS3的transform属性和transition属性,以及Vue的动态绑定class属性。以下是一个简单的实现思路: 1. 在组件中添加一个卡片容器,设置overflow: hidden属性和white-space: nowrap属性,使卡片可以水平滚动并且超出容器范围的部分被隐藏。 2. 使用flex布局,将卡片设置为均匀分布,并且设置卡片的z-index属性和transform属性,使卡片左右重叠。 3. 在卡片容器上添加touchstart、touchmove、touchend事件的监听函数。 4. 在touchstart事件中记录起始位置的横坐标和当前卡片的索引。 5. 在touchmove事件中计算当前位置的横坐标与起始位置的横坐标的差值,并根据差值设置卡片的transform属性。 6. 在touchend事件中判断差值是否超过一定的阈值,如果是则根据差值的正负来判断卡片是向左滑动还是向右滑动,并根据卡片的位置来设置是否切换到下一个卡片。 7. 使用Vue的动态绑定class属性来根据当前卡片的索引来设置卡片的z-index属性和transform属性,以实现左右重叠效果。 8. 使用CSS3的transition属性实现卡片的平滑过渡效果。 以下是一个简单的代码示例: ```html <template> <div class="card-container" @touchstart="onTouchStart" @touchmove="onTouchMove" @touchend="onTouchEnd"> <div class="card" :style="{ transform: `translateX(${translateX}px)`, zIndex: currentIndex }" :class="{ 'active': currentIndex === index }" v-for="(item, index) in items" :key="index"> {{ item }} </div> </div> </template> <script> export default { data() { return { items: ['Card 1', 'Card 2', 'Card 3', 'Card 4'], currentIndex: 0, startX: 0, translateX: 0 }; }, methods: { onTouchStart(event) { this.startX = event.touches[0].clientX; this.currentIndex = Math.floor(this.startX / (window.innerWidth / this.items.length)); }, onTouchMove(event) { const currentX = event.touches[0].clientX; this.translateX = currentX - this.startX; }, onTouchEnd(event) { const threshold = 50; if (Math.abs(this.translateX) > threshold) { this.currentIndex += this.translateX > 0 ? -1 : 1; if (this.currentIndex < 0) { this.currentIndex = 0; } else if (this.currentIndex >= this.items.length) { this.currentIndex = this.items.length - 1; } } this.startX = 0; this.translateX = 0; } } }; </script> <style scoped> .card-container { display: flex; overflow: hidden; white-space: nowrap; padding: 10px; } .card { flex: 0 0 80%; height: 200px; padding: 20px; background-color: #fff; box-shadow: 0 0 5px rgba(0, 0, 0, 0.3); transition: transform 0.3s ease-out, z-index 0s linear; } .card.active { flex: 0 0 100%; z-index: 2; transform: translateX(0) scale(1.1); } .card.active + .card { z-index: 1; transform: translateX(50%) scale(0.9); } .card.active + .card + .card { z-index: 0; transform: translateX(100%) scale(0.8); } </style> ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘斩仙的笔记本

富贵险中求

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值