<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<style type="text/css">
#field {
position: relative;
width: 400px;
height: 400px;
margin-left: 10%;
margin-top: 10%;
/*background-color: yellow;*/
border: 5px solid black;
}
.block {
position: relative;
width: 10px;
height: 220px;
background-color: rgba(255, 0, 0, 0.5);
}
#first,
#second,
#third,
#fourth,
#fifth{
position: absolute;
top: 15%;
left: 50%;
transform-origin: center 320px;
}
</style>
</head>
<body>
<div id="field">
<div id="first" class="animate">
<div class="block">1</div>
</div>
<div id="second">
<div class="block">2</div>
</div>
<div id="third">
<div class="block">3</div>
</div>
<div id="fourth">
<div class="block">4</div>
</div>
<div id="fifth">
<div class="block">5</div>
</div>
</div>
<input id="button" type="button" value="Push me!">
<script>
window.onload = function() {
console.log("VSE GOOD");
var $field = $("#field"),
block = $(".block"),
allBlockes = $("#field > div"),
len = allBlockes.length,
but = $("#button");
but.on("click", allBlockes, function() {
function AnimateRotate(el, d) {
$({
deg: 0
}).animate({
deg: d
}, {
step: function(now, fx) {
el.css({
transform: "rotate(" + now + "deg)"
})
}
})
}
var left = i = 0;
for (; i < len; i++) {
var el = allBlockes.eq(i);
if (i % 2) left += 15;
left = -left;
AnimateRotate(el, left)
}
})
};
</script>
</body>
</html>