Modifying Tooltip Coordinates with the jQuery Tooltip Plug-in - A final example with the top and left parameters
(Page 4 of 4 )
As I expressed in the previous section, I wish to end this article by showing you yet another code sample regarding the use of the "top" and "left" arguments. Of course, if you already grasped the example developed earlier, then I suggest that you to skip over this step and read the conclusion. Otherwise, take a look at the following code, which uses the aforementioned parameters with no mouse tracking:
<!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 400 ms, do not track mouse position, fade it and assign left-top coordinates
$(document).ready(function(){
$("a").tooltip({
delay: 400,
fade: 500,
top: -10,
left: 40
});
});
</script>
</head>
<body>
<ul>
<li><a href="http://jquery.com" title="Sample Link 1">Sample Link 1</a></li>
<li><a href="http://jquery.com" title="Sample Link 2">Sample Link 2</a></li>
<li><a href="http://jquery.com" title="Sample Link 3">Sample Link 3</a></li>
<li><a href="http://jquery.com" title="Sample Link 4">Sample Link 4</a></li>
<li><a href="http://jquery.com" title="Sample Link 5">Sample Link 5</a></li>
<li><a href="http://jquery.com" title="Sample Link 6">Sample Link 6</a></li>
</ul>
</body>
</html>
Here you have it. As I said before, the above example now specifies different coordinates for tooltips, but in this particular case, mouse tracking has been disabled. Here's a complementary screen shot that shows how tooltips are displayed on screen:

Logically, it's possible to create endless variations of the above code sample, but that would be rather pointless in this case. However, with all the material included in this tutorial, hopefully you'll have a solid guide to tweaking the behavior of tooltips using the "top" and "left" parameters.
Final thoughts
That's all for the moment. In this fourth part of the series, you learned how to use the handy "top" and "left" parameters that come bundled with the Tooltip jQuery plug-in to modify the default coordinates at which tooltips are displayed next to the targeted links.
In the next part of this series, I'm going to explain how to include HTML in tooltips, which can be very convenient for showing customized information on targeted web page links. Now that you've been warned, don't miss the next tutorial!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |