Javascript Tooltip Help And Color Change
I am fairly new with Javascript. Now, what I need is that I have a link in my projectXYZ which leads to another projectABC. I need to change the color of the link and show a toolt
Solution 1:
Usually it is said to be sufficient to add a 'title' attribute in tour DIV's and it will show up as tooltip on mouse-hover.
But to make a basic tooltip with proper positioning, you can use the below. I have used it and it works !!
JS (will have two mwthods, showTip and hideTip) :
<scripttype="text/javascript">functionshowtip(e,message) {
var x=0;
var y=0;
var m;
var h;
if(!e)
var e=window.event;
if(e.pageX||e.pageY) { x=e.pageX; y=e.pageY; }
elseif(e.clientX||e.clientY)
{ x=e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;y=e.clientY+document.body.scrollTop+document.documentElement.scrollTop;}
m=document.getElementById('myTooltip');
if((y>10)&&(y<450))
{ m.style.top=y-4+"px"; }
else{ m.style.top=y+4+"px"; }
var messageHeigth=(message.length/20)*10+25;
if((e.clientY+messageHeigth)>510)
{ m.style.top=y-messageHeigth+"px"; }
if(x<850) { m.style.left=x+20+"px"; }
else{ m.style.left=x-170+"px"; }
m.innerHTML=message;m.style.display="block";m.style.zIndex=203;
}
functionhidetip(){
var m;
m=document.getElementById('myTooltip');m.style.display="none";
}
</script>
CSS:
<styletype="text/css">#myTooltip{padding: 5px; background-color: #FFF8DC; border: 1px solid #DEB887; width:180px;font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #6b6b6b; display:none; position:absolute;left:0px;top:0px; }
</style>
And the HTML (will have an extra DIV below the href to show tooltip):
<ahref="javascript:void(0)"onmouseover="showtip(event, 'Sample tooltip text');"onmouseout="hidetip();">Hover mouse to see tooltip text.</a><divid="myTooltip" ></div>
Hope it helps !!
Post a Comment for "Javascript Tooltip Help And Color Change"