簡體   English   中英

我如何使用Javascript函數連續旋轉照片

[英]How do i continuously rotate a photo using Javascript function

我試圖找出在 Javascript 中連續旋轉圖像的邏輯。 到目前為止,我已經提出了這個代碼。 img1是圖像的 id,到目前為止它可以工作,但它只旋轉一次。 每次點擊它時如何讓它旋轉? 我正在使用onclick事件。

function rotateProfilePic() {
            var image = document.getElementById('img1');
            image.style.transform = "rotate(180deg)";
        } 

抱歉,如果這個問題對某人來說太簡單了,我是 Web 編程的初學者。

將您的功能設置為圖像上的點擊偵聽器:

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);

暫無
暫無

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

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