我試圖找出在 Javascript 中連續旋轉影像的邏輯。到目前為止,我已經提出了這個代碼。img1是影像的 id,到目前為止它可以作業,但它只旋轉一次。每次點擊它時如何讓它旋轉?我正在使用onclick事件。
function rotateProfilePic() {
var image = document.getElementById('img1');
image.style.transform = "rotate(180deg)";
}
抱歉,如果這個問題對某人來說太簡單了,我是 Web 編程的初學者。
uj5u.com熱心網友回復:
將您的功能設定為影像上的點擊偵聽器:
const imgTag = document.getElementById("img1");
const rotateStep = 180; // rotation size
let curImgAngle = 0;
function rotateProfilePic() {
curImgAngle = rotateStep;
imgTag.style.transform = `rotate(${curImgAngle}deg)`;
}
imgTag.addEventListener("click", rotateProfilePic);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/487378.html
標籤:javascript css 图片 回转 逻辑
上一篇:將bmp轉換為2d矩陣弄亂顏色
