您好,每次按下鍵盤上的任何鍵時,我都必須讓一個物件(在我的情況下是一個圓圈)移動 20 像素并滾動 180 度。
有人可以幫忙嗎?
uj5u.com熱心網友回復:
// declare initial values
let pos = 0
let rot = 0
// grab the element
const circle = document.querySelector('.circle')
// add listener for keydown event
document.addEventListener('keydown', () => {
// increase values
pos = 10
rot = 10
// use translate and rotate with the current values
circle.style.transform = `translateX(${pos}px) rotate(${rot}deg)`
})
.circle {
border-radius: 50%;
height: 200px;
width: 200px;
background: red;
display: flex;
justify-content: center;
align-items: center;
}
<div class="circle">text</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/522744.html
