jQuery Tooltip positioning issues
Posted
by Nimbuz
on Stack Overflow
See other posts from Stack Overflow
or by Nimbuz
Published on 2010-04-08T09:04:27Z
Indexed on
2010/04/08
9:33 UTC
Read the original article
Hit count: 620
HTML:
<a href="#" rel="tooltip-1">Open Tooltip</a>
<div id="tooltip-1">Tooltip Content</div>
jQuery:
xOffset = $('#tooltip-1').height() + 10;
yOffset = -30 ;
$("a[rel=tooltip-1]").hover(function(e){
this.t = this.attr("href");
$("body").append("<p id='tooltip'>"+ this.t +"</p>");
$("#tooltip")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
},
function(){
this.t = "";
$("#tooltip").remove();
});
$("a[rel=tooltip-1]").mousemove(function(e){
$("#tooltip-1")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
});
Two Issues:
- Tooltip div (#tooltip-1) doesn't hide on mouseout.
- Since the tooltip div will always have the same ID as REL, I'd like to modify the above jQuery so that it takes target DIV ID automatically.
Thanks in advance for your help.
© Stack Overflow or respective owner