簡體   English   中英

如何修改:animation 發生后的 hover 值並更改 h1 的字體大小?

[英]How do i modify :hover values after an animation has occurred and changed the font-size of an h1?

在發生 animation 並更改 h1 的字體大小后,我該如何修改:hover? 它是這樣的: text: font-size: 12.5rem; 字母間距:0; hover over the text- font-size: 13.5rem letter-spacing: 1rem; ,幾秒鍾后,帶有@keyframes 的 animation 出現,並且正在將字體大小從 12.5rem 更改為 5 rem。 應用了新的更改(字體大小:5rem;)我想再次對它進行 hover 但這次是:hover 的值要更改,當我 hover 的新值從動畫后變為 5 rem 和字母間距,從 1rem 開始; 到 0.2rem。 我不知道該怎么做..請幫我一些代碼

使用 vanilla Js 創建的解決方案

 let title = document.getElementById('title'); let i = 0; title.addEventListener('mouseover', function() { if (i >= 1) { hoverText(5, 6); title.removeEventListener('mouseover', function() {}); } else { hoverText(12.5, 13.5); i++; } }); function hoverText(small, big) { title.style.fontSize = big + "rem"; setTimeout(function() { title.style.fontSize = small + "rem"; }, 1000); }
 h1#title { font-size: 12.5rem; letter-spacing: 0; transition-duration: 1s; }
 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width. initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="style.css"> <script src="./script.js" defer></script> </head> <body> <h1 id="title">h1 element</h1> </body> </html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM