JSFiddle - React, Tailwind, and code Playground
HTML
<div class="tourne" style="border:1px solid #f00;width:200px;height:200px;position:absolute;top:50%;left:50%"></div>
<div class="tourne" style="border:1px solid #f00;width:200px;height:200px;position:absolute;top:10%;left:10%"></div>
<input type="button" id="lui" value="Fait tourner ce DIV !"/>
JavaScript
! function(e) {
e.fn.tournez = function(n) {
var a = {
angle: "180",
speed: "1000",
rewind: "false",
callback: null
},
t = e.extend(a, n);
return this.each(function() {
var n = e(this);
e({
deg: 0
}).animate({
deg: t.angle
}, {
duration: t.speed,
step: function(e) {
n.css({
transform: "rotate(" + e + "deg)"
})
},
complete: function() {
a.callback && !1 === t.rewind && a.callback(), !0 === t.rewind && e({
deg: t.angle
}).animate({
deg: 0
}, {
duration: t.speed,
step: function(e) {
n.css({
transform: "rotate(" + e + "deg)"
})
},
complete: function() {
a.callback && a.callback()
}
})
}
})
})
}
}(jQuery);
$("#lui").on("click",function(){
$(".tourne").tournez({angle:90,speed:500,rewind:true,callback:function(){alert('Please only once !')}})
})