Skip to content

Instantly share code, notes, and snippets.

@shrikanthkr
Created September 8, 2014 06:12
Show Gist options
  • Save shrikanthkr/c7b7d8ea40688dcb4027 to your computer and use it in GitHub Desktop.
Save shrikanthkr/c7b7d8ea40688dcb4027 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-git2.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
#parent{
width:40px;
height:40px;
background:green;
border-radius:50%;
position:relative;
}
.child{
width:40px;
height:40px;
background:red;
border-radius:50%;
position:absolute;
z-index:-10;
left:0px;
-webkit-transition: all .2s;
-moz-transition: all .2s;
transition: all .2s;
}
#parent:hover > .child{
background:yellow;
left:100px;
}
</style>
</head>
<body>
<div id="parent">
<div class="child">
</div>
<div class="child">
</div>
<div class="child">
</div>
<div class="child">
</div>
</div>
<script id="jsbin-javascript">
var parent = $('#parent'),
noOfChildren = parent.children().length,
angleRatio = (90/noOfChildren),
paddingDegree = 10;
angleRatio+=paddingDegree;
parent.hover(function(){
console.log('in'+angleRatio);
pitchOut();
},function(){
console.log('out');
pitchIn();
});
function pitchOut(){
var radius = 100;
parent.children().each(function(index){
var x = radius * cosDeg(index * angleRatio),
y = radius * sinDeg(index * angleRatio);
$(this).css({
left:x+'px',
top:y+'px'
});
});
}
function pitchIn(){
parent.children().each(function(){
$(this).css({
left:0+'px',
top:0+'px'
});
});
}
function sinDeg(num) {
return Math.sin(num/180*Math.PI);
};
function cosDeg(num) {
return Math.cos(num/180*Math.PI);
};
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-git2.js"><\/script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="parent">
<div class="child">
</div>
<div class="child">
</div>
<div class="child">
</div>
<div class="child">
</div>
</div>
</body>
</html></script>
<script id="jsbin-source-css" type="text/css">#parent{
width:40px;
height:40px;
background:green;
border-radius:50%;
position:relative;
}
.child{
width:40px;
height:40px;
background:red;
border-radius:50%;
position:absolute;
z-index:-10;
left:0px;
-webkit-transition: all .2s;
-moz-transition: all .2s;
transition: all .2s;
}
#parent:hover > .child{
background:yellow;
left:100px;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">var parent = $('#parent'),
noOfChildren = parent.children().length,
angleRatio = (90/noOfChildren),
paddingDegree = 10;
angleRatio+=paddingDegree;
parent.hover(function(){
console.log('in'+angleRatio);
pitchOut();
},function(){
console.log('out');
pitchIn();
});
function pitchOut(){
var radius = 100;
parent.children().each(function(index){
var x = radius * cosDeg(index * angleRatio),
y = radius * sinDeg(index * angleRatio);
$(this).css({
left:x+'px',
top:y+'px'
});
});
}
function pitchIn(){
parent.children().each(function(){
$(this).css({
left:0+'px',
top:0+'px'
});
});
}
function sinDeg(num) {
return Math.sin(num/180*Math.PI);
};
function cosDeg(num) {
return Math.cos(num/180*Math.PI);
};</script></body>
</html>
#parent{
width:40px;
height:40px;
background:green;
border-radius:50%;
position:relative;
}
.child{
width:40px;
height:40px;
background:red;
border-radius:50%;
position:absolute;
z-index:-10;
left:0px;
-webkit-transition: all .2s;
-moz-transition: all .2s;
transition: all .2s;
}
#parent:hover > .child{
background:yellow;
left:100px;
}
var parent = $('#parent'),
noOfChildren = parent.children().length,
angleRatio = (90/noOfChildren),
paddingDegree = 10;
angleRatio+=paddingDegree;
parent.hover(function(){
console.log('in'+angleRatio);
pitchOut();
},function(){
console.log('out');
pitchIn();
});
function pitchOut(){
var radius = 100;
parent.children().each(function(index){
var x = radius * cosDeg(index * angleRatio),
y = radius * sinDeg(index * angleRatio);
$(this).css({
left:x+'px',
top:y+'px'
});
});
}
function pitchIn(){
parent.children().each(function(){
$(this).css({
left:0+'px',
top:0+'px'
});
});
}
function sinDeg(num) {
return Math.sin(num/180*Math.PI);
};
function cosDeg(num) {
return Math.cos(num/180*Math.PI);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment