vue中動(dòng)態(tài)修改animation效果無效問題詳情
問題描述
鼠標(biāo)移入移出,并沒有出現(xiàn)閃動(dòng):
<template> <div class="alarmIcon" ref="alarmIcon" @mouseenter="handleEnter" @mouseleave="handleLeave" ></div> </template> <script> export default(){ mounted(){ }, methods:{ handleEnter(){ this.$refs['alarmIcon'].style.animation = 'blink 1s inifnite' }, handleLeave(){ this.$refs['alarmIcon'].style.animation = 'noBlink 1s inifnite' } } } </script> <style scoped> .alarmIcon { position: absolute; top: 50%; left: 50%; width: 100px; height: 100px; border-radius: 50%; transform: translate3d(-50%, -50%, 0); background: #008c8c; animation: noBlink 1s inifinite; } @keyframes blink { 0% { opacity: 1; } 100% { opacity: 0; } } @keyframes noBlink { 0% { opacity: 1; } 100% { opacity: 1; } } </style>
問題原因
樣式中添加了 scoped,會(huì)導(dǎo)致.alarmIcon
中的 animation 和 keyframe 中的動(dòng)畫會(huì)添加一個(gè)唯一標(biāo)識(shí),然后調(diào)用函數(shù)的時(shí)候 animation 是沒有對(duì)應(yīng)的標(biāo)識(shí)的。
解決辦法
將 keyframes 下的內(nèi)容放到 scoped 的外邊或者去掉 scoped
1.將 keyframes 下的內(nèi)容放到 scoped 的外邊
<style scoped> .alarmIcon { position: absolute; top: 50%; left: 50%; width: 100px; height: 100px; border-radius: 50%; transform: translate3d(-50%, -50%, 0); background: #008c8c; animation: noBlink 1s inifinite; } </style> <style> @keyframes blink { 0% { opacity: 1; } 100% { opacity: 0; } } @keyframes noBlink { 0% { opacity: 1; } 100% { opacity: 1; } } </style>
2.去掉scoped
<style> .alarmIcon { position: absolute; top: 50%; left: 50%; width: 100px; height: 100px; border-radius: 50%; transform: translate3d(-50%, -50%, 0); background: #008c8c; animation: noBlink 1s inifinite; } @keyframes blink { 0% { opacity: 1; } 100% { opacity: 0; } } @keyframes noBlink { 0% { opacity: 1; } 100% { opacity: 1; } } </style>
到此這篇關(guān)于vue中動(dòng)態(tài)修改animation效果無效問題詳情的文章就介紹到這了,更多相關(guān)vue animation 內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
element-plus 下拉框?qū)崿F(xiàn)全選的示例代碼
本文主要介紹了element-plus 下拉框?qū)崿F(xiàn)全選的示例代碼,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05基于Vue?+?ElementUI實(shí)現(xiàn)可編輯表格及校驗(yàn)
這篇文章主要給大家介紹了基于Vue?+?ElementUI?實(shí)現(xiàn)可編輯表格及校驗(yàn),文中有詳細(xì)的代碼講解和實(shí)現(xiàn)思路,講解的非常詳細(xì),有需要的朋友可以參考下2023-08-08vue中獲取滾動(dòng)table的可視頁面寬度調(diào)整表頭與列對(duì)齊(每列寬度不都相同)
這篇文章主要介紹了vue中獲取滾動(dòng)table的可視頁面寬度,調(diào)整表頭與列對(duì)齊(每列寬度不都相同),需要的朋友可以參考下2019-08-08vue項(xiàng)目中接入websocket時(shí)需要ip端口動(dòng)態(tài)部署問題
這篇文章主要介紹了vue項(xiàng)目中接入websocket時(shí)需要ip端口動(dòng)態(tài)部署問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09Vue引入vuetify框架你需要知道的幾點(diǎn)知識(shí)
這篇文章主要介紹了Vue引入vuetify框架你需要知道的幾點(diǎn)知識(shí),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06