The jQuery Flashlight Effect

Why? No reason, really. I had seen the idea demonstrated elsewhere and wanted to recreate the effect. Other than the novelty of it, I'm not sure where it might ever get used properly...

Here's how it works:

Everything is black: both the background color of the page and all text.
The body has a single background image: a flashlight beam on a wall (500x500 pixels)

The applicable CSS:

html, body{

	background-position:50% 50%;

The jQuery javascript framework is used to monitor mouse movement across the page:

<script type="text/javascript" src=""></script>
$(document).ready(function() {
$("body").css('background-position',(e.pageX - 250)+'px '+(e.pageY - 250)+'px');

If you decide to use your own image, you'll of course need to change the CSS reference to it, but also take note of the image dimensions. The jQuery code must position the background image exactly halfway under the mouse cursor...change each '250' as needed to match half the size of your image.

Back to Mantle Labs