js通用提示信息(tooltip)

function hideTip() { var fm = getTipDiv(); if (fm != undefined) { fm.style.display = "none"; } } function showTip(message, e) { var fm = getTipDiv(); var posX,posY; if (document.all) { posX = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft; posY = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop; } else if (e) { posX = document.body.scrollLeft + e.pageX; posY = document.body.scrollTop + e.pageY; } else { posX = 10; posY = 10; } var top = posY + 15; var left = posX + 5; fm.style.left = left + "px"; fm.style.top = top + "px"; fm.style.display = ""; fm.innerHTML = message; } var getTipDiv = function() { var id = "__popids"; var getObj = document.getElementById(id); if (getObj != undefined)return getObj; var div = document.createElement("DIV"); div.setAttribute("id", id); div.cssText = "-moz-opacity:.8;"; div.style.display = "none"; div.style.position = "absolute"; div.style.top = "0px"; div.style.left = "0px"; div.style.filter = "alpha(opacity=80)"; document.body.appendChild(div); return div; }

 

使用:

<a href="#" mce_href="#" onmouseout="hideTip()" onmousemove="showTip('<img src="images/mian11.jpg" mce_src="images/mian11.jpg" border=0><br/>可以是图片加文字',event)" >提示信息,显示图片与文字</b></a>

你可能感兴趣的:(function,div,border)