PDA

View Full Version : Resolved Rotate An Image Once



Deadweight
08-26-2014, 10:17 PM
Using JQuery 1.11 why does the img rotate and the input disappear:


$(function() {
var $elie = $("img"), degree = 0, timer;

function rotate() {

$elie.css({ WebkitTransform: 'rotate(' + degree + 'deg)'});
$elie.css({ '-moz-transform': 'rotate(' + degree + 'deg)'});
timer = setTimeout(function() {
++degree; rotate();
if(degree%360==0){clearTimeout(timer);}
},5);
}

$("input").toggle(function() {
clearTimeout(timer);
}, function() {
rotate();
});
});





<input type="button" value=" Toggle Spin " />
<br/><br/><br/><br/>
<img src="http://i.imgur.com/ABktns.jpg" />

Deadweight
08-26-2014, 11:02 PM
Resolved:


$(function() {
var $elie = $("img"), degree = 1, timer;

function rotate() {

$elie.css({ WebkitTransform: 'rotate(' + degree + 'deg)'});
$elie.css({ '-moz-transform': 'rotate(' + degree + 'deg)'});
timer = setTimeout(function() {
++degree; rotate();
if(degree%360==0){clearTimeout(timer);}
},5);
}

$("input").click(function() {

rotate();
});
});