Sonarr/NzbDrone.Web/Scripts2/Metro/tilt.js

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2013-01-17 00:39:42 +00:00
/*
Base off Tim Holman's tile tilt: http://tholman.com/experiments/css3/metro-tiles/
*/
function addTileTilt()
{
var tile = this;
var mouse = {x: 0, y: 0, down: false};
var maxRotation = 16;
var setRotation = function(){
var width = tile.offsetWidth;
var height = tile.offsetHeight;
//Rotations as percentages
var yRotation = (mouse.x - (width / 2)) / (width / 2);
var xRotation = (mouse.y - (height / 2)) / (height / 2);
tile.style.webkitTransform = "rotateX(" + -xRotation * maxRotation + "deg)" +
" rotateY(" + yRotation * maxRotation + "deg)";
tile.style.mozTransform = "rotateX(" + -xRotation * maxRotation + "deg)" +
" rotateY(" + yRotation * maxRotation + "deg)";
tile.style.transform = "rotateX(" + -xRotation * maxRotation + "deg)" +
" rotateY(" + yRotation * maxRotation + "deg)";
}
var MouseDown = function(e){
mouse.x = e.offsetX;
mouse.y = e.offsetY;
mouse.down = true;
setRotation();
}
var MouseUp = function(e){
mouse.down = false;
tile.style.webkitTransform = "rotateX(0deg)" +
" rotateY(0deg)";
tile.style.mozTransform = "rotateX(0deg)" +
" rotateY(0deg)";
tile.style.transform = "rotateX(0deg)" +
" rotateY(0deg)";
}
var MouseMove = function(e){
mouse.x = e.offsetX;
mouse.y = e.offsetY;
if (mouse.down == true){
setRotation();
}
}
tile.addEventListener('mousemove', MouseMove, false);
tile.addEventListener('mousedown', MouseDown, false);
tile.addEventListener('mouseup', MouseUp, false);
tile.addEventListener('mouseout', MouseUp, false);
}