Skip to content

Instantly share code, notes, and snippets.

@eliasgs
Created October 17, 2012 22:26
Show Gist options
  • Save eliasgs/3908732 to your computer and use it in GitHub Desktop.
Save eliasgs/3908732 to your computer and use it in GitHub Desktop.
<div id=wrapper>
<div class=seat></div>
<div class=seat></div>
<div class=seat></div>
<div class=seat></div>
<div class=seat></div>
</div>
jQuery(function ($){
var radius = 250;
var center = { left: 250, bottom: 500 };
var pi = Math.PI;
var distribute = { from: 5*pi/4, to: 7*pi/4 };
var curve = function (angle){
return {
left: radius*Math.cos(angle)+center.left,
bottom: radius*Math.sin(angle)+center.bottom
};
};
var n = $('.seat').length-1;
var delta = Math.abs(distribute.from-distribute.to)/n;
$('.seat').css('position', 'absolute');
$('.seat').css('margin', 0);
$('.seat').each(function (i,e){
var angle = i*delta+distribute.from;
var pos = curve(angle);
$(e).css({
left: pos.left,
bottom: pos.bottom,
'-webkit-transform': 'rotate(-'+angle+'rad)'
});
});
});
body { background: silver; }
#wrapper{
position: relative;
margin: 10px;
width: 500px;
height: 500px;
border: 1px dashed grey;
}
.seat{
float: left;
margin: 10px;
width: 50px;
height: 50px;
background: brown;
-webkit-transform-origin: center center;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment