Skip to content

Instantly share code, notes, and snippets.

@sunny
Created January 11, 2010 14:07
Show Gist options
  • Save sunny/274262 to your computer and use it in GitHub Desktop.
Save sunny/274262 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Lamp shadow</title>
<!-- Text-shadow that follows the user's mouse. Hurray! -->
<style>
#sun {
font:6em/1 sans-serif;
margin:2em auto 0 auto;
text-shadow:5px 5px 3px rgba(0,0,0,0.5);
width:1em;
height:1em;
text-align:center;
}
</style>
</head>
<body>
<div id="sun">☀</div>
<script>
var sun = document.getElementById('sun'),
centreX = sun.offsetLeft + sun.offsetWidth/2,
centreY = sun.offsetTop + sun.offsetHeight/2
document.getElementsByTagName('html')[0].onmousemove = function(e) {
var x = (centreX-e.clientX)*0.1,
y = (centreY-e.clientY)*0.1,
d = 50/(Math.abs(x)+Math.abs(y)),
b = d > 7 ? 7 : d;
sun.style.textShadow = x+'px '+y+'px '+b+'px rgba(0,0,0,.5)'
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment