Порой надо использовать подсказки к ссылкам, это можно сделать спомощью довольно простого кода. Ниже рассмотрим один из примеров!
В качестве картинок для оформления «подсказки» можно использовать фон – диалог.
1. HTML code:
<html><head> <title>ToolTip</title><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> <link rel="stylesheet" href="css/tooltip.css" media="screen"> <script type="text/javascript" src="js/tooltip.js"></script> </head> <body> <div id="bubble_tooltip"> <div class="bubble_top"><span></span></div> <div class="bubble_middle"><span id="bubble_tooltip_content">Content is comming here as you probably can see.Content is comming here as you probably can see.</span></div> <div class="bubble_bottom"></div> </div> <h1>DHTML ToolTip</h1> <p>Example:</p> <p><a href="#" onmouseover="showToolTip(event,'This is simple text!');return false" onmouseout="hideToolTip()"> its easy ?</p> <p>Another text - <a href="#" onmouseover="showToolTip(event,'Text');return false" onmouseout="hideToolTip()"> for exmple 2 </a> </p> </body> </html>
2. CSS code:
body{
padding-top:85px;
font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif;
font-size:0.9em;
line-height:130%
}
a{
color: #D60808;
text-decoration:none
}
a:hover{
border-bottom:1px dotted #317082;
color: #307082
}
#bubble_tooltip{
width:147px;
position:absolute;
display:none;
}
#bubble_tooltip .bubble_top{
background-image: url('../images/top.gif');
background-repeat:no-repeat;
height:16px;
}
#bubble_tooltip .bubble_middle{
background-image: url('../images/middle.gif');
background-repeat:repeat-y;
background-position:bottom left;
padding-left:7px;
padding-right:7px;
}
#bubble_tooltip .bubble_middle span{
position:relative;
top:-8px;
font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif;
font-size:11px;
}
#bubble_tooltip .bubble_bottom{
background-image: url('../images/bottom.gif');
background-repeat:no-repeat;
background-repeat:no-repeat;
height:44px;
position:relative;
top:-6px;
}
3. JS code:
function showToolTip(e,text){
if(document.all)e = event;
var obj = document.getElementById('bubble_tooltip');
var obj2 = document.getElementById('bubble_tooltip_content');
obj2.innerHTML = text;
obj.style.display = 'block';
var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0;
var leftPos = e.clientX - 100;
if(leftPos<0)leftPos = 0;
obj.style.left = leftPos + 'px';
obj.style.top = e.clientY - obj.offsetHeight -1 + st + 'px';
}
function hideToolTip()
{
document.getElementById('bubble_tooltip').style.display = 'none';
}
