$(document).ready(function() {
//Center the "info" bubble in the "circle" div
var divTop = ($("#divCircle").height() - $("#middleBubble").height()) / 2;
var divLeft = ($("#divCircle").width() - $("#middleBubble").width()) / 2;
$("#middleBubble").css("top", divTop + "px");
$("#middleBubble").css("left", divLeft + "px");
//Arrange the icons in a circle centered in the div
numItems = $("#divCircle img").length; //How many items are in the circle?
start = 0.0; //the angle to put the first image at. a number between 0 and 2pi
step = (4 * Math.PI) / numItems; //calculate the amount of space to put between the items.
//Now loop through the buttons and position them in a circle
$("#divCircle img").each(function(index) {
radius = ($("#divCircle").width() - $(this).width()) / 2.3; //The radius is the distance from the center of the div to the middle of an icon
//the following lines are a standard formula for calculating points on a circle. x = cx + r * cos(a); y = cy + r * sin(a)
//We have made adjustments because the center of the circle is not at (0,0), but rather the top/left coordinates for the center of the div
//We also adjust for the fact that we need to know the coordinates for the top-left corner of the image, not for the center of the image.
tmpTop = (($("#divCircle").height() / 2) + radius * Math.sin(start)) - ($(this).height() / 2);
tmpLeft = (($("#divCircle").width() / 2) + radius * Math.cos(start)) - ($(this).width() / 2);
start += step; //add the "step" number of radians to jump to the next icon
//set the top/left settings for the image
$(this).css("top", tmpTop);
$(this).css("left", tmpLeft);
});
});
$('.avatarList').click(function() {
$(this).toggleClass('expand');
$('#divCircle').toggleClass('expand');
});
$('#divCircle img').click(function() {
var theSrc = $(this).attr('src');
// alert(theSrc);
$('.mainImg img').attr('src', theSrc);
});
html {
background: #f2f6f8;
/* Old browsers */
background: -moz-linear-gradient(top, #f2f6f8 0%, #d8e1e7 50%, #b5c6d0 51%, #e0eff9 100%);
/* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #f2f6f8), color-stop(50%, #d8e1e7), color-stop(51%, #b5c6d0), color-stop(100%, #e0eff9));
/* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #f2f6f8 0%, #d8e1e7 50%, #b5c6d0 51%, #e0eff9 100%);
/* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #f2f6f8 0%, #d8e1e7 50%, #b5c6d0 51%, #e0eff9 100%);
/* Opera 11.10+ */
background: -ms-linear-gradient(top, #f2f6f8 0%, #d8e1e7 50%, #b5c6d0 51%, #e0eff9 100%);
/* IE10+ */
background: linear-gradient(to bottom, #f2f6f8 0%, #d8e1e7 50%, #b5c6d0 51%, #e0eff9 100%);
/* W3C */
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#f2f6f8', endColorstr='#e0eff9', GradientType=0);
/* IE6-9 */
}
.body {
width: 200px;
font-family: sans-serif;
margin: 10% auto;
text-align: center;
height: 200px;
}
#divCircle {
width: 195px;
height: 195px;
border-radius: 200px;
position: relative;
overflow: hidden;
top: -10px;
left: -10px;
opacity: 0;
margin: -60px;
-webkit-transition: opacity 0s 0s;
}
#divCircle img {
position: absolute;
width: 50px;
height: 50px;
background: orange;
border-radius: 60px;
border: 2px #000 solid;
-webkit-transition: all 0.4s;
}
#divCircle img:hover {
border: 2px #333 solid;
width: 55px;
height: 55px;
}
#middleBubble {
text-align: center;
vertical-align: top;
color: #252525;
/*#6d6e71*/
height: 60px;
width: 60px;
position: absolute;
text-align: center;
}
#middleBubble img {
top: 0px !important;
left: 0px !important;
}
.mainImg {
width: 60px;
position: absolute;
margin: -60px;
}
.mainImg img {
width: 60px;
border-width: 0px;
border-style: solid;
border-color: rgba(0, 0, 0, 0);
border-radius: 600px;
overflow: hidden;
-webkit-transition: all 0.5s;
margin: 60px 0 0 60px;
}
.avatarList {
margin: 0px -60px;
display: inline-block;
/* border:1px black solid; */
width: 60px;
height: 60px;
background: orange;
border-radius: 60px;
}
.avatarList.expand .mainImg img {
border-color: rgba(0, 0, 0, 1);
border-width: 60px;
margin: 0;
}
#divCircle.expand {
display: block;
opacity: 1;
-webkit-transition: opacity 0.5s 0.4s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="body">
<div>Click to pick avatar</div>
<br/>
<div class="avatarList">
<div class="mainImg">
<img src="http://png-1.findicons.com/files/icons/1072/face_avatars/300/i04.png">
</div>
<div id="divCircle">
<div id="middleBubble"></div>
<img src="http://png-1.findicons.com/files/icons/1072/face_avatars/300/a03.png">
<img src="http://png-3.findicons.com/files/icons/1072/face_avatars/300/c05.png">
<img src="https://gp5.googleusercontent.com/-esaz03FKsLU/AAAAAAAAAAI/AAAAAAAAAAA/kk0t9Rd9DB0/s48-c-k-no/photo.jpg">
<img src="http://www.veryicon.com/icon/png/Avatar/Face%20Avatars/Male%20Face%20G1.png">
<img src="http://icons.iconarchive.com/icons/hopstarter/face-avatars/256/Female-Face-FG-1-brunette-icon.png">
<img src="http://png-3.findicons.com/files/icons/1072/face_avatars/300/c05.png">
<img src="http://png-1.findicons.com/files/icons/1072/face_avatars/300/i04.png">
</div>
</div>
</div>
<!--body-->