vue中如何動態(tài)設(shè)置css樣式的hover
vue動態(tài)設(shè)置css樣式的hover
1.定義不同的顏色數(shù)組
colorList: ['#4cb352', '#5bc2d3', '#ffc23f', 'pink', '#872822'],//課件標(biāo)題顏色
2.html數(shù)據(jù)遍歷-自定義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" style="cursor: pointer;" @click="toDownload">
? ? ? ? ? ? ? 更多課件
? ? ? ? ? ? ? <img src="../../assets/img/more_class_btn.png" />
? ? ? ? ? ? </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="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 驅(qū)動的懸停效果,可應(yīng)用于鏈接、按鈕、徽標(biāo)、SVG、特色圖像等。
- 輕松應(yīng)用于您自己的元素、修改或僅用于靈感。
- 在 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"> ? ? 天天向上,好好學(xué)習(xí) </div>
.an {
? height: 100px;
? width: 200px;
? background-color: blueviolet;
? border-radius: 10px;
? float: left;
? margin: 10px;
? vertical-align: middle;
}4.拿到想要的樣式類名 通過f12查看div上面的class類名 點擊下面鏈接地址

總結(jié):以上四步就可以實現(xiàn)hover.css動畫的基本使用。
頁面所有代碼
<template>
<!-- http://ianlunn.github.io/Hover/ hover css動畫網(wǎng)址 -->
//圖層左彈出
<div class="an button hvr-bounce-to-left">
天天向上,好好學(xué)習(xí)
</div>
//圖層右彈出
<div class="an button hvr-sweep-to-right">
天天向上,好好學(xué)習(xí)
</div>
<div class="an button hvr-grow">天天向上,好好學(xué)習(xí)</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>以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue.js條件渲染和列表渲染以及Vue中key值的內(nèi)部原理
這篇文章主要介紹了Vue.js條件渲染和列表渲染,以及Vue中key值的內(nèi)部原理,文中有詳細(xì)的代碼示例,感興趣的同學(xué)可以參考閱讀2023-04-04
Vue表單校驗validate和validateField的使用及區(qū)別詳解
validateField?和?validate?都可以用于表單驗證,但是它們的作用有所不同,下面這篇文章主要給大家介紹了關(guān)于Vue表單校驗validate和validateField的使用及區(qū)別的相關(guān)資料,需要的朋友可以參考下2024-04-04
基于vue,vue-router, vuex及addRoutes進(jìn)行權(quán)限控制問題
這篇文章主要介紹了基于vue,vue-router, vuex及addRoutes進(jìn)行權(quán)限控制問題,需要的朋友可以參考下2018-05-05
如何使用vuejs實現(xiàn)更好的Form validation?
如何使用vuejs實現(xiàn)更好的Form validation?這篇文章主要介紹了vue-form插件的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-04-04
vue頁面設(shè)置滾動失敗的完美解決方案(scrollTop一直為0)
這篇文章主要介紹了vue頁面設(shè)置滾動失敗的解決方案(scrollTop一直為0),本文通過場景分析實例代碼相結(jié)合給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05

