JavaScript Page 2 - Interacting with Tooltips and Previews |
Example 4-8 shows the new JavaScript file. Example 4-8. Providing tooltips for form and other elements var xmlhttp; // global XMLHttpRequest obj // setup tooltip event // attach tooltip events to objects // get position // get XMLHttpRequest object if not set helpItem = (evnt.currentTarget) ? evnt.currentTarget.id : evnt.srcElement.id; // if cached item, print existing and return // invoke help system // hide help bubble //position tooltip View the tooltips in action in Figure4-2 .
Again, it seems a lot of code to create a simple effect, but it's also code that can be easily repackaged for use in a separate library. All you have to do is provide a way to create the tooltip object, passing in the location and content, and the tooltip object takes care of the rest. You could package more of the functionality, passing in just an element, and the tooltip object can take care of the event handling, though you'll most likely need to provide the content unless you embed the contents as elements in the page rather than pulling it in from a web service.
For effects such as those found on Netflix and Blockbuster, you'll need to provide an image that has a transparent background. The only way to do this is to use a transparent GIF or a PNG image, though the latter doesn't work that well with IE (not even with IE 7, which adds some odd color effects). You'll have to layer your effect, providing a header and footer image, and a separate body image that can repeat along the vertical axis so that it can be resized based on the length of the contents. One other important item to remember when providing this type of functionality is that tooltips don't work if scripting is disabled. However, one workaround is to provide hypertext links around the element to open a separate page and use anchors for individual help items.
blog comments powered by Disqus |