Hi
Following code in
Tooltip.css
.tooltip
{
position: absolute;
border: 1px solid #8EAACE;
background: #E9F2FF;
color: black;
padding: 3px 3px 3px 3px;
z-index: 1000;
display: none;
font-family: "Trebuchet MS" , Arial, Helvetica, sans-serif;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-khtml-border-radius: 5px;
overflow: hidden;
}
.tooltiptitle
{
font-weight: bold;
font-size: 12px;
}
.tooltipdetail
{
font-size: 11px;
}
following code in
Tooltip.js
var tooltipID;
var tooltipTitleID = 'dvTooltipTitle'
var tooltipTextID = 'dvTooltipText'
var animationSpeed = 10;
var tooltip;
var tooltipWidth;
var tooltipHeight;
var tooltipShowDelay = 500;
var tooltipTimer;
var tooltipAnimationTimer;
var isDisplayed = false;
var incrementX = 10;
var incrementY = 10;
function showTooltip(e, containerId, title, text) {
tooltipID = containerId;
tooltip = getElement(tooltipID);
if (typeof title != 'undefined' && title != '') getElement(tooltipTitleID).innerHTML = title;
if (typeof text != 'undefined' && text != '') getElement(tooltipTextID).innerHTML = text;
tooltipWidth = parseInt(tooltip.style.width);
tooltipHeight = parseInt(tooltip.style.height);
var position = positionTooltip(e);
tooltipTimer = setTimeout(function () { displayTooltip(position); }, tooltipShowDelay);
}
function displayTooltip(position) {
clearTimeout(tooltipTimer);
tooltip.style.left = position.Left + 'px';
tooltip.style.top = position.Top + 'px';
tooltip.style.height = "0px";
tooltip.style.width = "0px";
tooltip.style.display = 'block';
animateTooltip();
}
function positionTooltip(e) {
var currentX = (e.x) ? parseInt(e.x) : parseInt(e.clientX);
var currentY = (e.y) ? parseInt(e.y) : parseInt(e.clientY);
var mouseX;
var mouseY;
var height;
var width;
if (typeof (document.documentElement.clientWidth) == 'number') {
width = document.body.clientWidth;
height = document.body.clientHeight;
}
else {
width = parseInt(window.innerWidth);
height = parseInt(window.innerHeight);
}
mouseX = ((currentX + tooltipWidth + 10) < width) ? currentX + 10 : mouseX = currentX - tooltipWidth;
mouseY = ((currentY + tooltipHeight) < height) ? currentY : mouseY = currentY - tooltipHeight - 10;
if (window.pageYOffset) {
mouseY = mouseY + window.pageYOffset;
mouseX = mouseX + window.pageXOffset;
}
else {
mouseY = mouseY + document.body.scrollTop;
mouseX = mouseX + document.body.scrollLeft;
}
return { "Top": mouseY, "Left": mouseX };
}
function hideTooltip(element) {
clearTimeout(tooltipTimer);
clearTimeout(tooltipAnimationTimer);
tooltip.style.width = tooltipWidth + 'px';
tooltip.style.height = tooltipHeight + 'px';
tooltip.style.display = 'none';
}
function animateTooltip() {
var i = parseInt(tooltip.style.width) + incrementX;
var j = parseInt(tooltip.style.height) + incrementY;
tooltip.style.width = (i <= tooltipWidth) ? i + "px" : tooltip.style.width = tooltipWidth + "px";
tooltip.style.height = (j <= tooltipHeight) ? j + "px" : tooltip.style.height = tooltipHeight + "px";
var maxOriginalSize = Math.max(tooltipWidth, tooltipHeight);
var maxCurrentSize = Math.max(i, j);
var opacity = parseInt((100 * maxCurrentSize) / maxOriginalSize);
setOpacity(tooltip, opacity);
if (!((i > tooltipWidth) && (j > tooltipHeight)))
tooltipAnimationTimer = setTimeout("animateTooltip();", animationSpeed);
else
clearTimeout(tooltipAnimationTimer);
}
function setOpacity(element, iOpacity) {
var opacityAsDecimal = iOpacity;
if (iOpacity > 100)
iOpacity = opacityAsDecimal = 100;
else if (iOpacity < 0)
iOpacity = opacityAsDecimal = 0;
opacityAsDecimal /= 100;
if (iOpacity < 1) iOpacity = 1;
element.style.opacity = (opacityAsDecimal);
element.style.filter = "alpha(opacity=" + iOpacity + ")";
}
following code in
common.js
function setTooltip() {
var sPrefix = 'Tooltip.';
var docElemnts = document.getElementsByTagName('a');
for (var e = 0; e < docElemnts.length; e++) {
with (docElemnts[e]) {
if (getAttribute('rel') != undefined && getAttribute('rel') != null) {
var rel = getAttribute('rel');
if (rel.indexOf(sPrefix) >= 0) {
var key = rel.split(sPrefix)[1];
for (tip in aTooltips) {
var str = aTooltips[tip];
if (str.search(key) == 0) {
var Tooltip = str.split('¦')[1];
docElemnts[e].setAttribute('TooltipTitle', Tooltip.split('|')[0]);
docElemnts[e].setAttribute('TooltipDescription', Tooltip.split('|')[1]);
docElemnts[e].onmouseover = attachTooltip;
docElemnts[e].onmouseout = function () {
hideTooltip('dvTooltip');
}
break;
}
}
}
}
}
}
}
function attachTooltip(e) {
if (!e) var e = window.event;
showTooltip(e, 'dvTooltip', this.getAttribute('TooltipTitle'), this.getAttribute('TooltipDescription'));
}
function getElement(element) {
if (typeof element == 'object')
return element;
else
return document.getElementById(element);
}
you need to add in .aspx page
<script language="javascript" type="text/javascript" src="Tooltip.js"></script>
<script language="javascript" type="text/javascript" src="Common.js"></script>
<link href="Tooltip.css" type="text/css" rel="Stylesheet" />
add following attribute your
Anchor tag
rel="Tooltip.Search"
Tooltip.Search is automatically assign search Title and Description to the link this will be defined in common.js
div id="dvTooltip"
div with id dvTooltip which contain Title and Description container you can change style and format as per your requirement.
<div id="dvTooltip" class="tooltip" style="height: 50px; width: 160px;">
<div class="tooltiptitle" id="dvTooltipTitle">
</div>
<div class="tooltipdetail" id="dvTooltipText">
</div>
</div>
<a href="javascript:void(0)" rel="Tooltip.Search" >Search New</a>