下面鏈接的 Codepen 是我目前卡住的地方。
function startHover(e) {
btn.classList.add("btnPlaying")
}
function removeHover(e) {
btn.classList.remove("btnPlaying");
}
const btn = document.querySelector('.btn')
btn.addEventListener("mouseenter", startHover);
btn.addEventListener('transitionend', removeHover);
.btn {
margin-top: 10rem;
padding: 20px 100px;
background-color: rgb(255, 204, 3);
border-radius: 10px;
border-style: none;
box-shadow: 0px 0px 10px black;
color: blue;
border: 4px solid rgb(53, 106, 188);
transition: all 1.07s ease;
}
.btnPlaying {
transform: scale(1.1);
}
<button class="btn">Play!</button>
https://codepen.io/TerrellsCode/pen/zYEyORB
按鈕按預期增長和收縮,但只執行一次。只要用戶將滑鼠懸停在按鈕上,就可以尋找有關如何使此增長/縮小影片無限回圈的任何指示。謝謝
uj5u.com熱心網友回復:
不需要 JavaScript。使用 CSS 關鍵幀,您可以創建和運行影片。animation-play-state使用選擇器切換:hover以啟動和暫停影片。
@keyframes grow-shrink {
from {
transform: scale(1);
}
to {
transform: scale(1.1);
}
}
.btn {
margin-top: 10rem;
padding: 20px 100px;
background-color: rgb(255, 204, 3);
border-radius: 10px;
border-style: none;
box-shadow: 0px 0px 10px black;
color: blue;
border: 4px solid rgb(53, 106, 188);
animation-name: grow-shrink;
animation-duration: 1.07s;
animation-timing-function: ease;
animation-fill-mode: backwards;
animation-direction: alternate;
animation-play-state: paused;
animation-iteration-count: infinite;
}
.btn:hover {
animation-play-state: running;
}
<button class="btn">Play!</button>
uj5u.com熱心網友回復:
你不需要 javascript 來創建這樣的影片,使用 css 關鍵幀和無限影片。
.btn {
margin-top: 10rem;
padding: 20px 100px;
background-color: rgb(255,204,3);
border-radius: 10px;
border-style: none;
box-shadow: 0px 0px 10px black;
color: blue;
border: 4px solid rgb(53,106,188);
}
.btn:hover {
animation: btnPlaying 1s infinite;
}
@keyframes btnPlaying {
0% {
transform: scale(1);
}
50% {
transform: scale(1.1);
}
100% {
transform: scale(1);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/414292.html
標籤:
上一篇:WPF我在顯示按鈕圖片時遇到問題(當滑鼠懸停在按鈕上時,影像將隱藏)
下一篇:將四個輸入設定為看起來像一個
