I am trying to create a rotating fan simulation using JavaScript & Jquery. My output runs fine 1st time, but when I first stop the fan rotation to zero, and start again the counter value starts from last position of setInterval, is there any way to set it to zero, if once I have reduced the fan speed to zero or how can I use static variable(like in Java) where any operation on the variable reflects throughout program ? I tried windows.variable, .variable, but result is the same. Please help My JS and jquery code:
var angle = 0;
var movement;
$(".fan-start").click(function(){
$(".counter").html(window.movement);
window.movement = setInterval(fanOps,1);
});
$(".fan-stop").click(function(){
clearInterval(window.movement);
window.movement--;
if(window.movement>=0)
{
$(".counter").html(window.movement);
}
});
function fanOps()
{
if(angle<360)
{
angle ++;
}
else{
angle = 0;
}
$("img").css("transform","rotate("+angle+"deg)");
}
.counter is the class of the counter value. A screenshot is attached of the page..
My fan operation is working absolutely fine, my issue is setting the counter value back at zero from setInterval, when I start again after bringing it to zero once.