vue动态设置css样式的hover

1.定义不同的颜色数组

colorList: ['#4cb352', '#5bc2d3', '#ffc23f', 'pink', '#872822'],//课件标题颜色

2.html数据遍历-自定义element-走马灯高度+定义css变量-yf-border-color

 <div
            v-for="(item, index) in listData"
            :key="`${index}`"
            :class="`partCurriculum`"
            :style="`color:${colorList[index]};--yf-border-color:${colorList[index]}`"
          >
            <div class="partCurriculumTitle">{{ item.subjectName }}</div>
            <div class="moreLink" @click="toDownload">
              更多课件
              <img src="" />
            </div>
            <el-carousel
              trigger="click"
              :autoplay="false"
              class="partCurriculumVideo"
              :height="
                item.courseWaresList[0].length > 6
                  ? '740px'
                  : item.courseWaresList[0].length <= 3
                  ? '250px'
                  : '500px'
              "
            >
              <el-carousel-item
                v-for="(tItem,tIndex) in item.courseWaresList"
                :key="`${tItem}${tIndex}`"
                class="video_connent"
              >
                <div
                  v-for="(LItem,LIndex) in tItem"
                  :class="`videoBlock`"
                  :key="`${LItem}${LIndex}`"
                >
                  <img :src="https://www.jb51.net/article/LItem.coursewareImg" alt="正在加载,请耐心等待" /> 
                </div>
              </el-carousel-item>
            </el-carousel>

3.css添加hover

  .videoBlock {
    position: relative;
    width: 29%;
    height: 220px;
    box-sizing: border-box;
    color: #ccc;
    &:hover {
      border: 4px solid var(--yf-border-color, #4cb352);
    }
    img {
      width: 100%;
      height: 100%;
      display: block;
    }
  }

vue使用hover.css动画

介绍:

  • 一组 CSS3 驱动的悬停效果,可应用于链接、按钮、徽标、SVG、特色图像等。
  • 轻松应用于您自己的元素、修改或仅用于灵感。
  • 在 CSS、Sass 和 LESS 中可用。

1.下载hover.css

npm i hover.css --save

2. 全局映入css

import 'hover.css'

3.使用类,加上类名 button hvr-bounce-to-left

<div class="an  button hvr-bounce-to-left">
    天天向上,好好学习
</div>
.an {
  height: 100px;
  width: 200px;
  background-color: blueviolet;
  border-radius: 10px;
  float: left;
  margin: 10px;
  vertical-align: middle;
}

4.拿到想要的样式类名 通过f12查看div上面的class类名 点击下面链接地址

hover.css 链接地址

vue中如何动态设置css样式的hover

总结:以上四步就可以实现hover.css动画的基本使用。

页面所有代码

<template>
<!-- http://ianlunn.github.io/Hover/ hover  css动画网址 -->
//图层左弹出
<div class="an  button hvr-bounce-to-left">
天天向上,好好学习
</div>
//图层右弹出
<div class="an  button hvr-sweep-to-right">
天天向上,好好学习
</div>
<div class="an button hvr-grow">天天向上,好好学习</div>
</template>
<script lang="ts">
import { defineComponent } from "vue";
import "hover.css";
export default defineComponent({
setup() {},
});
</script>
<style scoped>
.an {
height: 100px;
width: 200px;
background-color: blueviolet;
border-radius: 10px;
float: left;
margin: 10px;
vertical-align: middle;
}
</style>

以上为个人经验,希望能给大家一个参考,也希望大家多多支持本站。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。