vue中如何動態(tài)設(shè)置css樣式的hover
vue動態(tài)設(shè)置css樣式的hover
1.定義不同的顏色數(shù)組
colorList: ['#4cb352', '#5bc2d3', '#ffc23f', 'pink', '#872822'],//課件標題顏色
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)用于鏈接、按鈕、徽標、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中使用v-if,v-else來設(shè)置css樣式的步驟
我們在使用vue項目開發(fā)時,v-if是使用的非常多的,在這里我們談?wù)勅绾问褂胿-i來綁定修改css樣式,使用的主要是雙向數(shù)據(jù)綁定,即通過改變他的狀態(tài)來改變他的樣式,這篇文章主要介紹了vue中如何使用v-if,v-else來設(shè)置css樣式,需要的朋友可以參考下2023-03-03vue中使用vue-router切換頁面時滾動條自動滾動到頂部的方法
這篇文章主要介紹了vue項目中在使用vue-router切換頁面的時候滾動條自動滾動到頂部的實現(xiàn)方法,一般使用Window scrollTo() 方法實現(xiàn),本文給大家簡單介紹了crollTop的使用,需要的朋友可以參考下2017-11-11vue實現(xiàn)鼠標移過出現(xiàn)下拉二級菜單功能
這篇文章主要介紹了vue實現(xiàn)鼠標移過出現(xiàn)下拉二級菜單功能,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-12-12vue3項目中配置sass,vite報錯Undefined mixin問題
這篇文章主要介紹了vue3項目中配置sass,vite報錯Undefined mixin問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-02-02Vue結(jié)合Video.js播放m3u8視頻流的方法示例
本篇文章主要介紹了Vue+Video.js播放m3u8視頻流的方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-05-05