基于jquery的氣泡提示效果
初步測(cè)試暫未發(fā)現(xiàn)大的BUG,總體來(lái)說(shuō)不滿意的是鼠標(biāo)移來(lái)移去不斷觸發(fā)氣泡時(shí)會(huì)出現(xiàn)XX為空或不是對(duì)象的問(wèn)題,
雖然不影響效果,但看著IE左下角的黃色警告不爽,暫時(shí)不知道如何改進(jìn). 加了try/catch解決...
還有就是氣泡默認(rèn)出現(xiàn)在觸發(fā)對(duì)象的正上方,當(dāng)觸發(fā)對(duì)象在邊上時(shí),氣泡會(huì)有一部分出現(xiàn)在窗口外面......也許這種情況可以讓氣泡顯示在左邊或是右邊,感覺可能會(huì)有些麻煩,就沒去弄了,比較懶......
越用jquery就越喜歡用它...
bubble.js:
/*
* @date: 2010-5-30 11:57:22
* @author: 胡靈偉
* Depends:
* jquery.js
*
* function:氣泡提示效果
* use:$("selectors").bubble({fn:getdata, width:width, height:height});
* 對(duì)所有需要?dú)馀萏崾拘Ч膶?duì)象使用bubble方法,
* fn為氣泡中顯示內(nèi)容獲得方法,即fn中返回的數(shù)據(jù)會(huì)顯示在氣泡中
* 以樣式指代div則有:
* width\height為contents的width\height屬性
* 氣泡總width為left.width + contents.width + right.width
* 氣泡總height為top.height + contents.height + bottom.height
*/
(function ($) {
$.fn.bubble = function (options) {
Bubble = function(){
this.defaults = {
distance : 10,
time : 250,
hideDelay : 500,
width:100,
height:100
};
this.options = $.extend(this.defaults, options);
this.hideDelayTimer = new Array();
this.shown = new Array();
this.beingShown = new Array();
this.popup = new Array();
this.trigger = new Array();
this.makebubble = function(w, h){
var tpl = $('<div class="bubble-popup"></div>').append('<div class="topleft"></div>').append('<div class="top"></div>')
.append($('<div class="topright"></div>')).append('<div class="left"></div>')
.append('<div class="contents"></div>').append('<div class="right"></div>')
.append('<div class="bottomleft"></div>')
.append($('<div class="bottom"></div>')
.append($('<div class="bottomtail"></div>')))
.append('<div class="bottomright"></div>').appendTo('body');
tpl.find('.left, .right, .contents').each(function(){$(this).height(h)});
tpl.find('.top, .bottom, .contents').each(function(){$(this).width(w)});
return tpl;
};
this.add = function(triggers, options){
//此處的options為每次調(diào)用add方法傳進(jìn)來(lái)的參數(shù),比如指定獲取數(shù)據(jù)的方法fn, 氣泡寬width高h(yuǎn)eight
//console.debug("length:"+triggers.length);
var t = this.trigger.length;
//將新加入的需要?dú)馀萏崾拘Ч膶?duì)象放到trigger數(shù)組中
for(var j =0;j<triggers.length;j++)
this.trigger.push(triggers[j]);
//console.debug("trigger.length:" + this.trigger.length);
var hout = this.handleout;
var hover = this.handleover;
var obj = this;
//為新加入的對(duì)象綁定鼠標(biāo)監(jiān)聽事件
triggers.each(function(ind){
$(this).unbind('mouseover').mouseover(function(){
hover(t + ind, obj, options);
}).unbind('mouseout').mouseout(function(){
hout(t + ind, obj, options);
});
});
};
this.handleover = function(i, obj, options){
//console.debug("hideDelayTimer.length:" + obj.hideDelayTimer.length);
//當(dāng)新觸發(fā)冒氣泡事件時(shí)原先的定時(shí)器還沒結(jié)束則將原來(lái)的定時(shí)器清除
if (obj.hideDelayTimer[i]) clearTimeout(obj.hideDelayTimer[i]);
if (obj.beingShown[i] || obj.shown[i]) {
//如果氣泡正在冒或已經(jīng)冒出來(lái)了則不再重復(fù)冒氣泡
return;
} else {
var trigger = $(obj.trigger[i]);
//標(biāo)記正在冒氣泡
obj.beingShown[i] = true;
//創(chuàng)建氣泡
obj.popup[i] = obj.makebubble(options.width||obj.options.width, options.height||obj.options.height);
//對(duì)于氣泡綁定同樣的事件以使得鼠標(biāo)離開觸發(fā)對(duì)象后放到氣泡上時(shí)氣泡不會(huì)消失
obj.popup[i].mouseover(function(){obj.handleover(i, obj)}).mouseout(function(){obj.handleout(i, obj)});
//調(diào)用獲取數(shù)據(jù)的方法fn來(lái)顯示數(shù)據(jù)
obj.options.fn(obj.trigger[i], function(data){
obj.popup[i].find('.contents').text(data);
});
//設(shè)定氣泡的位置和顯示屬性,氣泡默認(rèn)出現(xiàn)在觸發(fā)對(duì)象正上方
obj.popup[i].css({
top: trigger.offset().top-obj.popup[i].height(),
left: trigger.offset().left + trigger.width()/2 - obj.popup[i].width()/2,
display: 'block'
}).animate(
//由于萬(wàn)惡的IE不能同時(shí)支持PNG半透明和濾鏡,所以對(duì)于IE不使用濾鏡
$.browser.msie?{
top: '-=' + obj.options.distance + 'px'
}:{
top: '-=' + obj.options.distance + 'px',
opacity: 1
}, obj.options.time, 'swing', function() {
obj.beingShown[i] = false;
obj.shown[i] = true;
});
}
return false;
};
this.handleout = function(i, obj, options){
//console.debug("hideDelayTimer["+i+"]:"+obj.hideDelayTimer[i]);
//處理當(dāng)因?yàn)槟承┮馔獠僮魇沟脹]有觸發(fā)鼠標(biāo)進(jìn)入事件而直接再次觸發(fā)鼠標(biāo)離開事件時(shí)的情況
if (obj.hideDelayTimer[i]) clearTimeout(obj.hideDelayTimer[i]);
obj.hideDelayTimer[i] = setTimeout(function () {
obj.hideDelayTimer[i] = null;
try{
obj.popup[i].animate(
$.browser.msie?{
top: '-=' + obj.options.distance + 'px'
}:{
top: '-=' + obj.options.distance + 'px',
opacity: 0//漸隱效果
}, obj.options.time, 'swing', function () {
obj.shown[i] = false;
obj.popup[i].css('display', 'none');
obj.popup[i] = null;
});}catch(e){};
}, obj.options.hideDelay);
return false;
};
};
$.bubble = new Bubble();//單例
$.bubble.add(this, options);
};
})(jQuery);
使用方法:(用到的圖片樣式img.zip,注意路徑,沒圖片是很難看的...)
<style type="text/css" media="screen">
<!--
* {
margin: 0;
padding: 0;
}
body {
padding: 10px;
}
h1 {
margin: 14px 0;
font-family: 'Trebuchet MS', Helvetica;
}
.bubbletrigger {
}
/* Bubble pop-up */
.bubble-popup {
position: absolute;
display: none;
z-index: 50;
border-collapse: collapse;
}
.bubble-popup .topleft {width:19px; height:15px;float:left;background-image: url(../images/bubble/bubble-1.png);}
.bubble-popup .top { width:1px;height:15px;float:left;background-image: url(../images/bubble/bubble-2.png); }
.bubble-popup .topright { width:19px; height:15px;float:left;background-image: url(../images/bubble/bubble-3.png); }
.bubble-popup .left { clear:left;width:19px; height:1px;float:left;background-image: url(../images/bubble/bubble-4.png); }
.bubble-popup .contents {
white-space:normal;
word-break:break-all;
float:left;
font-size: 12px;
line-height: 1.2em;
background-color: #fff;
color: #666;
font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", sans-serif;
}
.bubble-popup .right { width:19px; height:1px;float:left;background-image: url(../images/bubble/bubble-5.png); }
.bubble-popup .bottomleft { clear:left;width:19px; height:15px;float:left;background-image: url(../images/bubble/bubble-6.png); }
.bubble-popup .bottom {width:1px;height:15px;float:left;background-image: url(../images/bubble/bubble-7.png); text-align: center;}
.bubble-popup .bottomtail { width:30px; height:29px; display: block; margin: 0 auto; background-image: url(../images/bubble/bubble-tail2.png);}
.bubble-popup .bottomright { width:19px; height:15px;float:left;background-image: url(../images/bubble/bubble-8.png); }
-->
</style>
<script src="../js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="../js/bubble-1.0.js" type="text/javascript"></script>
<script type="text/javascript"><!--
aa = function(obj, callback){
$.ajax({
type : 'POST',
data : {word:$(obj).attr('alt'),rand:Math.random()},
url : 'http://localhost/xun/ajax.svl?method=getdetailinfo',
dataType : 'text',
timeout : 1000,
success : function(data){
callback(data);
}
});
};
bb = function(obj, callback){
$.ajax({
type : 'POST',
data : {word:$(obj).attr('alt'),rand:Math.random()},
url : 'http://localhost/xun/ajax.svl?method=getdetailinfo',
dataType : 'text',
timeout : 1000,
success : function(data){
callback(data + "aaaa");
}
});
};
$(function(){
$('.bubbletrigger').bubble({width:150, height: 100, fn:aa});
$('#a').bubble({fn:bb});
});
//
--></script>
</head>
<body id="page">
<h1>jQuery Bubble Example</h1>
<div>
<br/>aaaaaaaaaa
<br/>aaaaaaaaaaaaaaaaaaaa
<br/>aaaaaaaaaaaaaaaaaaaaaaaaaaaa
<br/>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
<br/>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
<br/>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</div>
<div style="padding-left:100px;">
<img class="bubbletrigger" alt="a" src="../images/bubble/starburst.gif" />
<img class="bubbletrigger" alt="b" src="../images/bubble/starburst.gif" />
<img class="bubbletrigger" alt="c" src="../images/bubble/starburst.gif" />
<img class="bubbletrigger" alt="d" src="../images/bubble/starburst.gif" />
<img id="a" alt="e" src="../images/bubble/starburst.gif" />
</div>
</body>
servlet只要返回一段字符串就可以了,就不貼了.
- 使用jQuery UI的tooltip函數(shù)修飾title屬性的氣泡懸浮框
- JQuery實(shí)現(xiàn)簡(jiǎn)單時(shí)尚快捷的氣泡提示插件
- jquery.cvtooltip.js 基于jquery的氣泡提示插件
- Jquery插件分享之氣泡形提示控件grumble.js
- jQuery插件HighCharts實(shí)現(xiàn)氣泡圖效果示例【附demo源碼】
- jQuery bt氣泡實(shí)現(xiàn)懸停顯示及移開隱藏功能的方法
- jquery實(shí)現(xiàn)鼠標(biāo)滑過(guò)顯示提示框的方法
- 基于JQuery 的消息提示框效果代碼
- Jquery實(shí)現(xiàn)鼠標(biāo)移上彈出提示框、移出消失思路及代碼
- jquery懸浮提示框完整實(shí)例
- jQuery實(shí)現(xiàn)鼠標(biāo)放置名字上顯示詳細(xì)內(nèi)容氣泡提示框效果的方法分析
相關(guān)文章
jQuery插件JWPlayer視頻播放器用法實(shí)例分析
這篇文章主要介紹了jQuery插件JWPlayer視頻播放器用法,結(jié)合實(shí)例形式分析了JWPlayer插件播放視頻的相關(guān)操作技巧,需要的朋友可以參考下2017-01-01
jquery基于layui實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)下拉選擇(省份城市選擇)
本篇文章主要介紹了jquery基于layui實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)下拉選擇(省份城市選擇),具有一定的實(shí)用價(jià)值,需要的朋友可以參考下2017-06-06
easyui Draggable組件實(shí)現(xiàn)拖動(dòng)效果
Draggable是easyui中用于實(shí)現(xiàn)拖拽功能的一個(gè)插件。利用它,我們可以實(shí)現(xiàn)控件的拖拽效果。Draggble覆蓋默認(rèn)值$.fn.draggable.defaults。2015-08-08
jquery動(dòng)畫4.升級(jí)版遮罩效果的圖片走廊--帶自動(dòng)運(yùn)行效果
我將上一章中了插件做了個(gè)小小的升級(jí),實(shí)現(xiàn)了自動(dòng)運(yùn)行效果,完整代碼大家見demo2012-08-08
jquery點(diǎn)擊頁(yè)面任何區(qū)域?qū)崿F(xiàn)鼠標(biāo)焦點(diǎn)十字效果
鼠標(biāo)點(diǎn)擊聚焦,地圖定位,在圖片上突出顯示,焦點(diǎn)定位頁(yè)面元素,這些都是在系統(tǒng)開發(fā)是經(jīng)常需要用到的,下面為大家介紹下具體的實(shí)現(xiàn),感興趣的朋友可以參考下哈2013-06-06
jquery ajax學(xué)習(xí)筆記2 使用XMLHttpRequest對(duì)象的responseXML
使用XMLHttpRequest對(duì)象的responseXML的方式來(lái)接受XML數(shù)據(jù)對(duì)象的DOM對(duì)象2011-10-10
Jquery選擇器簡(jiǎn)明版?Jquery選擇器實(shí)用版
最近需要用jquery獲取一些dom數(shù)據(jù)的操作,發(fā)現(xiàn)jquery的選擇器非常強(qiáng)大,很方便進(jìn)行一些dom操作,下面就專門針對(duì)這塊內(nèi)容做個(gè)簡(jiǎn)單的介紹,需要的朋友可以參考下2023-05-05
jquery fancybox ie6不顯示關(guān)閉按鈕的解決辦法
本篇文章主要是對(duì)jquery fancybox ie6不顯示關(guān)閉按鈕的解決辦法進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-12-12

