基于jquery的自定義鼠標提示效果 jquery.toolTip
更新時間:2010年11月14日 22:34:27 作者:
看到其它網(wǎng)站A標簽title效果,心里癢癢,就想也用到自己網(wǎng)站上。
正好在學jquery 插件擴展,就參照前輩代碼,自己動手寫了一個
IE下效果
//版權(quán) 酷車中國 www.kuchechina.com
//作者 逐月 zhuyue.cnblogs.com
//演示 http://www.kuchechina.com/carstools/Default.aspx
jQuery.fn.toolTip = function() {
this.unbind().hover(
function(e) {
this.t = this.title;
this.title = '';
$('body').append( '<p id="p_toolTip" style="display:none; max-width:320px;text-align:left;"><img id="img_toolTip_Arrow" src="images/arrow.gif" />' + this.t + '</p>' );
var tip = $('p#p_toolTip').css({ "position": "absolute", "padding": "10px 5px 5px 10px", "left": "5px", "font-size": "14px", "background-color": "white", "border": "1px solid #a6c9e2","line-height":"160%", "-moz-border-radius": "5px", "-webkit-border-radius": "5px", "z-index": "9999"});
var target = $(this);
var position = target.position();
this.top = (position.top - 8); this.left = (position.left + target.width() + 5);
$('p#p_toolTip #img_toolTip_Arrow').css({"position": "absolute", "top": "8px", "left": "-6px" });
tip.css({"top": this.top+"px","left":this.left+"px"});
tip.fadeIn("slow");
},
function() {
this.title = this.t;
$("p#p_toolTip").fadeOut("slow").remove();
}
);
};
使用方法:
<script type="text/javascript">
$(document).ready(function(){
$("#tootlsMain img[title]").toolTip();
});
</script>
可以利用jquery 選擇器,選擇帶title屬性的標簽,當然可以適當?shù)男薷拇a使適用帶alt屬性標簽。
title屬性支持簡單html標簽。如<br/>等。注意引號的使用
實現(xiàn)原理:
利用標簽title屬性,使hover事件取代默認鼠標事件,顯示浮動層。this.unbind().hover 就是這句代碼。jquery幫我們做好很多事情。堆積我們的現(xiàn)實代碼就行。
程序員,文筆一般希望您能看懂。
代碼下載
Firefox或其它瀏覽器效果
代碼
復(fù)制代碼 代碼如下:
//版權(quán) 酷車中國 www.kuchechina.com
//作者 逐月 zhuyue.cnblogs.com
//演示 http://www.kuchechina.com/carstools/Default.aspx
jQuery.fn.toolTip = function() {
this.unbind().hover(
function(e) {
this.t = this.title;
this.title = '';
$('body').append( '<p id="p_toolTip" style="display:none; max-width:320px;text-align:left;"><img id="img_toolTip_Arrow" src="images/arrow.gif" />' + this.t + '</p>' );
var tip = $('p#p_toolTip').css({ "position": "absolute", "padding": "10px 5px 5px 10px", "left": "5px", "font-size": "14px", "background-color": "white", "border": "1px solid #a6c9e2","line-height":"160%", "-moz-border-radius": "5px", "-webkit-border-radius": "5px", "z-index": "9999"});
var target = $(this);
var position = target.position();
this.top = (position.top - 8); this.left = (position.left + target.width() + 5);
$('p#p_toolTip #img_toolTip_Arrow').css({"position": "absolute", "top": "8px", "left": "-6px" });
tip.css({"top": this.top+"px","left":this.left+"px"});
tip.fadeIn("slow");
},
function() {
this.title = this.t;
$("p#p_toolTip").fadeOut("slow").remove();
}
);
};
使用方法:
復(fù)制代碼 代碼如下:
<script type="text/javascript">
$(document).ready(function(){
$("#tootlsMain img[title]").toolTip();
});
</script>
可以利用jquery 選擇器,選擇帶title屬性的標簽,當然可以適當?shù)男薷拇a使適用帶alt屬性標簽。
title屬性支持簡單html標簽。如<br/>等。注意引號的使用
實現(xiàn)原理:
利用標簽title屬性,使hover事件取代默認鼠標事件,顯示浮動層。this.unbind().hover 就是這句代碼。jquery幫我們做好很多事情。堆積我們的現(xiàn)實代碼就行。
程序員,文筆一般希望您能看懂。
代碼下載
您可能感興趣的文章:
- jquery tools之tooltip
- jQuery Tools tooltip使用說明
- jQuery帶箭頭提示框tooltips插件集錦
- 使用jQuery UI的tooltip函數(shù)修飾title屬性的氣泡懸浮框
- 25個優(yōu)雅的jQuery Tooltip插件推薦
- qTip 基于JQuery的Tooltip插件[兼容性好]
- Jquery實現(xiàn)自定義tooltip示例代碼
- jQuery插件Tooltipster實現(xiàn)漂亮的工具提示
- jquery插件tooltipv頂部淡入淡出效果使用示例
- jQuery自制提示框tooltip改進版
- jQuery實現(xiàn)ToolTip元素定位顯示功能示例
相關(guān)文章
jQuery實現(xiàn)鼠標經(jīng)過提示信息的地圖熱點效果
這是一個升級版本,更新了一個在IE8里的小問題,加入了提示框的內(nèi)容自動換行處理(北京點上有演示)!估計差不多該是最后樣式了。IE6、IE8、谷歌、火狐、測試正常。2015-04-04jQuery實現(xiàn)網(wǎng)頁抖動的菜單抖動效果
這篇文章主要介紹了jQuery實現(xiàn)網(wǎng)頁抖動的菜單抖動效果,鼠標滑過菜單項可見到菜單項的抖動效果,涉及jquery鼠標事件及頁面元素樣式動態(tài)操作的技巧,需要的朋友可以參考下2015-08-08使用DataTable插件實現(xiàn)異步加載數(shù)據(jù)
本文給大家分享的是Jquery+dataTable插件來實現(xiàn)異步加載數(shù)據(jù)的示例代碼,非常實用,有需要的小伙伴可以參考下2017-11-11jQuery實例—選項卡的簡單實現(xiàn)(js源碼和jQuery)
下面小編就為大家?guī)硪黄猨Query實例—選項卡的簡單實現(xiàn)(js源碼和jQuery) 。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06