Home arrow JavaScript arrow Page 3 - Building Image-Based Tooltips with the jQuery Tooltip Plug-in
JAVASCRIPT

Building Image-Based Tooltips with the jQuery Tooltip Plug-in


In this sixth part of a seven-part series on using the jQuery Tooltip plug-in, I demonstrate how the bodyHandler argument can be used to display image-based tooltips. I also show how to customize their behavior by adding and removing options within the “tooltip()” method.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
November 03, 2009
TABLE OF CONTENTS:
  1. · Building Image-Based Tooltips with the jQuery Tooltip Plug-in
  2. · Reintroducing the bodyHandler argument
  3. · Using the bodyHandler parameter to create image-based tooltips
  4. · Building an image tooltip with mouse tracking disabled

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Building Image-Based Tooltips with the jQuery Tooltip Plug-in - Using the bodyHandler parameter to create image-based tooltips
(Page 3 of 4 )

Certainly, one common usage of the “bodyHandler” argument is for creating image-based tooltips. Basically, this process permits you to display enlarged versions of thumbnail graphics by means of a simple callback function. To demonstrate this concept more extensively, I’m going to build a primitive JavaScript application that will show the full-sized version of a thumbnail, using the following sample image:

 

 

Now that there’s a graphic to work with, here’s the code sample that creates the image-based tooltip, based on the functionality given by the “bodyHandler” option:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Tooltip example using the bodyHandler option</title>

<link rel="stylesheet" type="text/css" href="jquery.tooltip.css" />

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript" src="jquery.dimensions.js"></script>

<script type="text/javascript" src="jquery.tooltip.js"></script>

<script type="text/javascript">

// assign tooltip to links after web page has been loaded

// delay tooltip display 400 ms, using bodyHandler option

$(document).ready(function(){

$("img").tooltip({

delay: 100,

track: true,

fade: 250,

bodyHandler: function() {

return $("<img />").attr("src", this.src);

}

});

});

</script>

</head>

<body>

<div>

<img src="sample_image.gif" width="125" height="100" alt="Sample Image" />

</div>

</body>

</html>

As you can see above, the dimensions of the sample image shown previously have been purposely reduced within the structural markup, while the callback function defined for the “bodyHandler” argument returns its full-sized version, thus creating a simple preview mechanism for a single thumbnail graphic. In addition, the following screen capture shows more clearly the output generated by this particular example:

 

 

Not too bad, huh? Considering that building this application requires only defining a simple callback function, the result is more than acceptable. In addition, it’s possible to create variations of the application by removing and adding some extra parameters passed to the “tooltip()” method. In the above example, it’s clear to see that the mouse tracking feature has been enabled, but it can be easily disabled while keeping the others active.

So, as a conclusion to this tutorial, I’m going to create a final hands-on example that will show how to build a slightly different version of the previous web application, where mouse tracking will be inactive. As usual, this process will be discussed in detail in the section to come, so click on the link below and read the following segment.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials