Created
June 8, 2010 09:38
-
-
Save sgruhier/429820 to your computer and use it in GitHub Desktop.
Demo page of CSS3 transform/transition with some JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ballon { | |
-webkit-transition: all .2s ease-in-out; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img src="balloon.png" id="balloon"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
function $(id) { return document.getElementById(id); } | |
var x, y, bx = 0, by = 0, angle, balloon = $('balloon'); | |
document.addEventListener('mousemove', function(event) { | |
x = event.pageX; | |
y = event.pageY; | |
}); | |
function updatePos() { | |
var dx = x - bx - 30, | |
dy = y - by, | |
nangle = Math.atan(dx/dy), | |
nbx = x - 35, | |
nby = y - 165; | |
balloon.style.webkitTransform = "translateY(" + Math.min(y, Math.abs(dx/2)) + "px) translateX(" + nbx + "px) rotate(" + nangle + "rad)"; | |
bx = nbx; | |
by = nby; | |
angle = nangle; | |
} | |
setInterval(updatePos, 150); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment