Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7030771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:42:56+00:00 2026-05-28T00:42:56+00:00

I have a function that makes a gear rotate on the page after an

  • 0

I have a function that makes a gear rotate on the page after an element is clicked, i found the code online and edited a little bit to make it compatible with what i need, however i cannot figure out how to make it run on a timer (maybe 2 seconds?). can anyone give me a hand?

$(".go1").click(function() {
    var $spin = $(".gear1"), degree = 0, timer;
    rotate();
    function rotate() {

        $spin.css({ WebkitTransform: 'rotate(' + degree + 'deg)'});  
        $spin.css({ '-moz-transform': 'rotate(' + degree + 'deg)'});
    timer = 2000,setTimeout(function() {
            ++degree; rotate();
        },50);

    }


});

http://jsfiddle.net/Y2tjX/

this is how it looks, the jsfiddle isnt working though (maybe i didnt put enough of the code) but in the whole of the actual file, the gear spins as desired when go1 is clicked but doesnt stop spinning

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:42:57+00:00Added an answer on May 28, 2026 at 12:42 am

    Forked from roXon: http://jsfiddle.net/HWfMt/

    The key is to stop the recursive setTimeout() calls after 2 seconds, each time you click.

    var degree = 0;
    var timer=30;
    var $spin = $(".gear1");
    var to;
    
    $(".go1").click(function() {
        rotate();
         setTimeout(function(){
         clearTimeout(to);
     },2000);
    
    });
    
    function rotate() {
        degree++;
        $spin.css({ 'WebkitTransform': 'rotate(' + degree + 'deg)'});  
        $spin.css({ '-moz-transform': 'rotate(' + degree + 'deg)'});
        to = setTimeout(function() {
            rotate();
        }, timer);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a function that makes ajax calls once an element is clicked.
I have a function that makes a series of calls to sscanf() and then,
I have a python function that makes a subprocess call to a shell script
I have link that calls a function when clicked: <a href=javascript:spawnMenu(this); id=link1>Test1</a> To make
In my Java code I have function that gets file from the client in
I have a function that makes ajax GET request and based on the value
I have a JavaScript function that makes two consecutive Ajax requests using jQuery. I
I have the following Javascript function that makes a call to an Asp.Net WebMethod
I have a function that makes a jQuery Ajax call to the BART api
I have a a link that calls a onmouseover javascript function that makes a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.