0

fiddle link

Hello, I am using this jQueryRotate plugin to rotate my div's after a user clicks on the button.

I would like to stop stacking the rotation after the button is clicked more than once. It just keeps on speeding up.

I have researched it and using .stop() nor return false; wont help. All I want is to know, whether there is a way to reset the rotation on the next click, or stop it after clicking on another button. Thanks a lot!

Marek
  • 307
  • 3
  • 13
  • Just a quick note, I found its a bug, the rotation speed is not increasing. If I change tabs and return back to the jsfiddle the speed has returned to normal. It is some sort of rendering glitch. – Cyassin Apr 02 '14 at 01:55

1 Answers1

1

The glitch came from having the declaration multiple times in the loop. I pulled the variables outside the click event which stopped the glitch.

To prevent the speed increasing, i did a quick check to see if the button had already been clicked. See below

$(document).ready(function () {
    var angle = 0
    var angleone = 0;
    var clicked = false;
    $('.concept').click(function () {
        if (!clicked) {
            setInterval(function () {
                angle += 3;
                $(".gear").rotate(angle);
            }, 50);

            setInterval(function () {
                angleone -= 3;
                $(".gear-one").rotate(angle);
            }, 50);
            clicked = true;
        }
    });
    $('.bar').click(function () {
        if ($('#default').is(':visible')) {
            $('#default').fadeOut(200);
        };
    });
});
Cyassin
  • 1,437
  • 1
  • 15
  • 31
  • Thanks a lot! That's exactly what I wanted to do, just didn't really know how! :) Anyway, you made my day! :) A quick note, why does the grey square not rotate counter-clockwise, since it has -= 3 degrees iterator? – Marek Apr 02 '14 at 08:22
  • 1
    I just realised it is because for gear-one the code is using angle not angleone on the rotate function. – Cyassin Apr 02 '14 at 22:17
  • It doesnt change anything... Can you please provide jsfiddle? – Marek Apr 02 '14 at 22:26