Home arrow JavaScript arrow Page 2 - More Uses for the jQuery Tooltip Plug-in`s bodyHandler Option
JAVASCRIPT

More Uses for the jQuery Tooltip Plug-in`s bodyHandler Option


Welcome to the final installment of a series on the jQuery Tooltip plug-in. In seven approachable tutorials, this series shows you how to use this powerful JavaScript application to create all sorts of eye-popping tooltips for your web page links. This will make them much more accessible and usable to your potential visitors.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
November 04, 2009
TABLE OF CONTENTS:
  1. · More Uses for the jQuery Tooltip Plug-in`s bodyHandler Option
  2. · Review: building an image tooltip
  3. · Assigning different coordinates to the image-based tooltip
  4. · Building a tooltip application with the fade out effect disabled

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
More Uses for the jQuery Tooltip Plug-in`s bodyHandler Option - Review: building an image tooltip
(Page 2 of 4 )

Since my plan here consists of creating a simple image-based tooltip that will look pretty similar to the ones built in the preceding installment of the series, it won’t hurt to recall how they were developed, right? Please take a fresh look at the complete source code for these sample tooltips:

(example on building an image-based tooltip with mouse tracking enabled)

 

<!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>

 

 

(example on building an image-based tooltip with mouse tracking disabled)

 

<!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</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 200 ms, using bodyHandler and fade options

$(document).ready(function(){

$("img").tooltip({

delay: 200,

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 shown above, the first example shows how to build a basic previewing mechanism for a thumbnail image, by means of the already familiar “bodyHandler” option. In this particular case, the full image will be displayed next to the corresponding thumbnail, and it’ll follow all of the mouse movements, since the “track” option has been assigned a value of TRUE. On the other hand, the second example implements a similar previewing system, but with a subtle difference, since the mouse tracking feature has been disabled.

To complement the two previous code samples, here’s a screen shot that shows the output they generate:

 

 

At this point you hopefully recalled how the previous code samples do their business, so it’s time to continue developing some interesting variations of image-based tooltips. Basically, in the next few lines I’m going to create an application like this, but where the default coordinates at which the tooltip will be displayed on screen will be modified via the “top” and “left” arguments. You'll probably recall our discussion of these arguments in some preceding tutorials.

Of course, the full details regarding the development of this new tooltip application will be given in the following section. Therefore, click on the link shown below and keep reading.


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 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials