Skip to content

Instantly share code, notes, and snippets.

@jiin
Last active August 29, 2015 14:25
Show Gist options
  • Save jiin/f761f69edab624011838 to your computer and use it in GitHub Desktop.
Save jiin/f761f69edab624011838 to your computer and use it in GitHub Desktop.
cool image animation
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Your Website</title>
<style>
body {
overflow: hidden;
}
div#timewarp-parent {
width: 700px;
height: 700px;
background-image: url('test.gif');
background-repeat: no-repeat;
background-position: center center;
border-radius: 50%;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
position: absolute;
}
div#timewarp-parent div {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
border-radius: 50%;
background-image: url('test.gif');
background-repeat: no-repeat;
background-position: center center;
-webkit-transform: translate3d(0, 0, 0);
-webkit-backface-visibility: hidden;
-webkit-perspective: 1000;
}
</style>
</head>
<body>
<div id="timewarp-parent"></div>
<script>
window.onload = function() {
var parent = document.getElementById('timewarp-parent');
var circles = 20;
var circle = [];
var baseHeight = 700;
var baseWidth = 700;
var offset = 30;
var transform = function() {
for(var i = 0; i < circles; i++) {
circle[i] = document.createElement('div');
circle[i].style.width = baseWidth - (offset * i) + 'px';
circle[i].style.height = baseHeight - (offset * i) + 'px';
circle[i].style['z-index'] = i + 1;
parent.appendChild(circle[i]);
}
};
transform();
document.addEventListener('mousemove', function(e) {
for(var i = 0; i < circles; i++) {
circle[i].style.transform = 'rotate(' + i * (e.pageX / 100 % 90) + 'deg)';
}
}, false);
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment