SpriteHand
Module Border
  Groovy, Shadowy Tooltips
Module Border
Location: BlogsAndy's Blog    
Posted by: host 5/18/2006 12:30 AM

With all the neat-o AJAX and Atlas sites showing up, one of the recurring things I've noticed is groovy, shadowy tooltips. What am I talking about? If you haven't tried Netflix yet, at least visit their site and try hovering over a movie image. You'll see a nice popup flash up with title details. I really like the shadows that show up around this popup, it really adds a professional touch.

So how is this done? Well, it should be possible to use PNG images to define an alpha channel that supports transparency. Most browsers except Internet Explorer support this. But in order to support the most browsers, you have to use a klugey method that uses an AlphaImageLoader Filter in IE. I'll show some code that implements this kluge, but first let's look at how we can create a PNG file that has this nice alpha channel...

I'll be using Paint.NET because it's free and it does a fine job of managing layers and transparency for PNG's!

(1) Create a new image by selecting File/New. Be sure to input your desired height and width.

(2) Set the image background to transparent by selecting Layers/Layer Properties and setting the Opacity to 0.

(3) In this step we will create the shadow layer
Select Layers/Add New Layer. Select the “Draw filled shape with outline” option button on the toolbar.

(4) Set both the foreground and background colors to a dark gray

 

(5) Draw out a rectangle (or other shape) for the background shadow.

 

 (6) Next, blur the shadow by selecting Effects/Blurs/Gaussian. Note how the “shadow” gets blurred out!

(7) Next, we add the “real object” that is casting the shadow. Overlay another rectangle or other object that is casting the shadow.

That's it! We now have a nice PNG file that can implement alpha transparency. But in order to get this to work cross-browser, we need to do a couple of dirty, kludgey things.

First, we need to have a "bogus proxy image" that is at least 1x1 pixel and completely transparent. You can create a 1x1 GIF image that is completely transparent, that will work fine. Let's call that image bogusPixel.gif.

Next, we need some javascript that will figure out if we are in IE and need to apply an AlphaImageLoader filter. This is because IE doesn't really support alpha channel PNG's, but has a filter that does support them.

<script language="javascript">
   
var bInitialized;
    function showImg(id) {
        var img = document.getElementById(id);
        img.style.visibility=
'visible';
        if (navigator.appVersion.indexOf("MSIE")>-1) {
            if (!bInitialized) {
                bInitialized =
true;
                img.style.width = img.width;
                img.style.height = img.height;
                img.style.filter =
"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='scale', src='" + img.src + "')";
                img.src =
"images/bogusPixel.gif";
            }
        }
    }

    function hideImg(id) {
        document.getElementById(id).style.visibility=
'hidden';
    }

script>

And FINALLY we can implement our little tooltip!

<img id="imgBalloonTip" src="images/Balloon.png" style="visibility:hidden">

<div style="width:50px; border:solid 2px Black;" onmouseover="showImg('imgBalloonTip');" onmouseout="hideImg('imgBalloonTip');">
   
Try Me
div>



And that's about it. So to give this a try, hover over the "Try This" div below and you'll see a groovy shadowy popup:
Try Me
Permalink |  Trackback

Title:
Comment:
Add Comment   Cancel 
Module Border Module Border
Module Border
  Blog_List
Module Border
Module Border Module Border
Module Border
  Subscribe
Module Border

RSS

Module Border Module Border
Module Border
  Diversions
Module Border

DESTROY ALL INVADERS
A scrolling shooter game where the objective is to destroy the invading UFO's flying over a neighborhood of your choosing. Imagery provided by Microsoft Virtual Earth. Created using Silverlight 2.
PLAY IT

INFO AND CODE



HOOK SHOT
This little basketball game was submitted as an entry to the TeamZoneSports Silverlight Contest. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

INFO AND CODE



SORT THE FOOBARS
A game where you need to sort the good foobars from the bad ones. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



POLYGON PHYSICS DEMO
A demo showing polygon physics where the user draws physics objects with the mouse. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



SILVERLIGHT ROCKS!
Destroy the asteroids before they destroy your ship! Created using Silverlight 2.
PLAY IT

INFO AND CODE



FISH GAME
A simple game of harpoon-the-fish. Written using the AJAX Sprite Toolkit.
PLAY IT

INFO AND CODE

Module Border Module Border
Module Border
  Search_Blog
Module Border
Module Border Module Border
Module Border
  Blog_Archive
Module Border
Module Border Module Border
Copyright (c) 2008 andy.beaulieu.com - Login