• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

196
Views
How do i continuously rotate a photo using Javascript function

I'm trying to figure out logic to continuously rotate an image in Javascript. So far I have came up to this code. img1 is the id of the image and so far it works but it rotates only once. How do I make it rotate every time I click on it? Im using onclick event.

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

Sorry if the question is too simple for someone, I'm beginner in Web Programming.

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Set your function as clicks listener on image:

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);
almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error