Monday, June 21, 2010

CSS3 Full-Screen Gradient Flashlight (jQuery)

Want to share a small tech-demo which simulates a moving flashlight (spotlight) over your web-site (without using Adobe Flash). The light is following mouse cursor. Uses jQuery. See the screenshot and the corresponding code:
   .fl {
    background-image: -moz-radial-gradient(center 45deg, circle closest-corner, rgba(255, 255, 255, 0) 0%, rgba(0, 0, 0, 255) 10%);
       background-image: -webkit-gradient(radial, center center, 0, center center, 350, from(rgba(255, 255, 255, 0)), to(rgba(0, 0, 0, 255)));
    width: 5000px;
    height: 5000px;
    position: absolute;
  <script type="text/javascript"
  <script type='text/javascript'>
            top: (e.pageY - 2500) + "px",
            left: (e.pageX - 2500) + "px"

 <body style="
  height: 100%;
  margin: 0;
  padding: 0;
  background: url(;
  overflow-x: hidden;
  <div class="fl" id="fl">

Update: the challenge was though to make links and buttons clickable still even though they are covered with a full-screen div. Luckily Firefox supports which is just one line in CSS that makes the div transparent for the clicks. Naturally IE doesn't support this feature so a small jQuery code is looking for any links at the current mouse pointer coordinates and propagates a click on a covering DIV to the underlying links.

1 comment:

moooo said...

Thanks for sharing, do you have any tips for getting this to work on my canvas ipad animation? The height/width of 5000px seems to cause problems, I'm not sure how to fix it.