vue--横向切换手风琴动画效果demo + div悬浮感(hover属性触发)

本文介绍了一个使用Vue.js实现的图片轮播组件,该组件利用了动态绑定和事件监听来实现图片的高亮显示和鼠标悬停效果。通过v-for循环遍历图片列表并为每个图片元素添加了动态类名和事件处理器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述
html:

<div class="or-container">
              <div class="box" :class="eleindex ==i?'eleactive':''" v-for="(ele,i) in piclist" :key="i" @mouseenter="enter(i)" @mouseleave="out(i)">
                <img :src="ele.img">
                <span>{{i}}</span>
              </div>

data:

data () {
      return {
        eleindex: 0,
        piclist: [
          {text: '播放/录制页面', bg: require('../../static/assets/images/home-pic/home-pic1.jpg'), img: '../../static/assets/images/home-pic/home-pic1.jpg'},
          {text: '播放/录制页面', bg: require('../../static/assets/images/home-pic/home-pic1.jpg'), img: '../../static/assets/images/home-pic/home-pic1.jpg'},
          {text: '播放/录制页面', bg: require('../../static/assets/images/home-pic/home-pic1.jpg'), img: '../../static/assets/images/home-pic/home-pic1.jpg'},
          {text: '播放/录制页面', bg: require('../../static/assets/images/home-pic/home-pic1.jpg'), img: '../../static/assets/images/home-pic/home-pic1.jpg'},
          {text: '播放/录制页面', bg: require('../../static/assets/images/home-pic/home-pic1.jpg'), img: '../../static/assets/images/home-pic/home-pic1.jpg'}

        ]
      }
    },

methods:

enter: function (i) {
        console.log(i)
        this.eleindex = i
        // if (this.eleindex === i) {
        //   this.eleindex = -1
        // } else {
        //   this.eleindex = i
        // }
      },
      out: function (i) {
        this.imgindex = -1
      }

css:

/*手风琴样式*/
.or-container {
  display: flex;
  width: 100%;
  padding: 4% 2%;
  box-sizing: border-box;
  height: 48vh;
}
.or-container:before {
  background-color: rgba(0,0,0,0.4);
}

.box {
  flex: 1;
  overflow: hidden;
  transition: .5s;
  box-shadow: 0 20px 30px rgba(0, 0, 0, 0.1);
  line-height: 0;
}

.box > img {
  width: 100%;
  height: calc(100% - 10vh);
  -o-object-fit: cover;
  object-fit: cover;
  transition: .5s;
}

.box > span {
  font-size: 3.8vh;
  display: block;
  text-align: center;
  height: 10vh;
  line-height: 2.6;
}

.eleactive {
  flex: 1 1 15%;
}

.eleactive > img {
  width: 100%;
  height: 100%;
}
  /*end*/

div悬浮感
效果很不错

样式:box-shadow: 2px 2px 5px #bbb;

可以给img 添加hover属性

.eleactive > img:hover {
  box-shadow: 2px 2px 5px #bbb;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值