本文實例講述了jquery實現簡單文字提示效果。分享給大家供大家參考,具體如下:
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>jquery實現簡單文字提示</title><style type="text/css">#preview{border:2px solid #c7c7c7; background:#e3f4f9; padding:5px; display:none; position:absolute;}</style><script src="jquery-1.2.6.pack.js" type="text/javascript"></script></head><body><a class="preview" title="看看提示出現了沒">移到我身上來?。?lt;/a><script type="text/javascript">this.imagePreview = function(){ /* CONFIG */ xOffset = 10; yOffset = 20; // 可以自己設定偏移值/* END CONFIG */$("a.preview").hover(function(e){ this.t = this.title; this.title = ""; var c = (this.t != "") ? "" + this.t : ""; $("body").append("<div id='preview'>"+ c +"</div>"); $("#preview") .css("top",(e.pageY - xOffset) + "px") .css("left",(e.pageX + yOffset) + "px") .fadeIn("fast"); },function(){ this.title = this.t; $("#preview").remove(); }); $("a.preview").mousemove(function(e){ $("#preview") .css("top",(e.pageY - xOffset) + "px") .css("left",(e.pageX + yOffset) + "px");}); };// 頁面加載完執行$(document).ready(function(){imagePreview();});</script></body></html>
jquery-1.2.6.pack.js插件點擊此處本站下載。
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答