本文實例講述了jQuery實現ToolTip元素定位顯示功能的方法。分享給大家供大家參考,具體如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題頁</title><script type="text/javascript" src="jquery-1.4.2.min.js" ></script><script type="text/javascript"> function ShowTip(event,obj,message) { var xOffset = -10; // x distance from mouse var yOffset = 10; // y distance from mouse //obj.style.top = (event.clientX + yOffset)+"px"; //obj.style.left = (event.clientY + xOffset)+"px"; //獲取元素width: $(obj).width(); //獲取元素height:$(obj).height() //獲取元素位置:$(obj).position().top和$(obj).offset().top $('body').append( '<div id="tipmessage">'+message+'</div>'); $('div#tipmessage').css("top", $(obj).position().top+$(obj).height() + "px").css("left", $(obj).position().left+"px").fadeIn("slow"); } function HideTip() { $("div#tipmessage").fadeOut("slow").remove(); } </script> <style type="text/css"> #tipmessage { display:none; z-index:1000; border:1px solid #448833; position:absolute; background:#ffffff; max-width:200px; max-height:30px; padding:5px 10px; }</style></head><body><a href="#" onmouseover="ShowTip(event,this,'歡迎訪問武林網')" onmouseout="HideTip()">Tip</a></body></html>運行效果截圖如下:

更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結》、《jQuery擴展技巧總結》、《jQuery切換特效與技巧總結》、《jQuery遍歷算法與技巧總結》、《jQuery常見經典特效匯總》、《jQuery動畫與特效用法總結》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答