betway必威-betway必威官方网站
做最好的网站

必威官方网站:JQuery达成轻巧前卫快速的血泡提

在程序提交后,我们供给表达并提醒出错的职责,利用JQuery大家能够轻巧达成气泡提醒,先看作用图:

代码注释已经竭尽的详细了,也非常少说了.
最先测量检验暂未察觉大的BUG,总体来讲不顺心的是鼠标移来移去不断触发气泡时会现出XX为空或不是指标的难题,
纵然不影响效应,但望着IE左下角的桃色警告不爽,前段时间不领悟怎么样革新. 加了try/catch消除...
还应该有正是气泡暗中同意出现在触及对象的正上方,当接触对象在一侧时,气泡会有一对出现在窗口外面......大概这种景观能够让气泡展现在侧边或是右侧,认为大概会稍为麻烦,就没去弄了,比较懒......
越用jquery就越喜欢用它...
bubble.js:

必威官方网站 1

复制代码 代码如下:

具体调用代码

/*
* @date: 2010-5-30 11:57:22
* @author: 胡灵伟
* Depends:
* jquery.js
*
* function:气泡提醒意义
* use:$("selectors").bubble({fn:getdata, width:width, height:height});
* 对具备需求气泡提醒成效的靶子使用bubble方法,
* fn为气泡中突显内容获取格局,即fn中回到的数据会显示在气泡中
* 以体制指代div则有:
* widthheight为contents的widthheight属性
* 气泡总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为每一遍调用add方法传进来的参数,比方钦命获取数据的办法fn, 气泡宽width高height
//console.debug("length:" triggers.length);
var t = this.trigger.length;
//将新投入的急需气泡提示成效的靶子放置trigger数组中
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;
//为新步向的靶子绑定鼠标监听事件
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);
//当新触发冒气泡事件时原先的电火花计时器还没甘休则将本来的电磁照应计时器清除
if (obj.hideDelayTimer[i]) clearTimeout(obj.hideDelayTimer[i]);
if (obj.beingShown[i] || obj.shown[i]) {
//假使气泡正在冒或已经冒出来了则不再重复冒气泡
return;
} else {
var trigger = $(obj.trigger[i]);
//标识正在冒气泡
obj.beingShown[i] = true;
//创建气泡
obj.popup[i] = obj.makebubble(options.width||obj.options.width, options.height||obj.options.height);
//对于气泡绑定同样的平地风波以使得鼠标离开触发对象后放置气泡上时气泡不会消失
obj.popup[i].mouseover(function(){obj.handleover(i, obj)}).mouseout(function(){obj.handleout(i, obj)});
//调用获取数据的章程fn来展现数据
obj.options.fn(obj.trigger[i], function(data){
obj.popup[i].find('.contents').text(data);
});
//设定气泡的岗位和显示属性,气泡暗中同意出现在触及对象正上方
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(
//由于万恶的IE无法同不常间帮助PNG半晶莹剔透和滤镜,所以对于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]);
//处理当因为一些意外操作使得尚未触发鼠标踏向事件而直白再一次触发鼠标离开事件时的事态
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,注意路线,没图片是很掉价的...)

<input name="ipt" id="ipt" value=""/>
<script language="javascript">
Tooltip.show('输入值为空!','ipt');
</script>

复制代码 代码如下:

其促成进度如下

<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 : '',
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 : '',
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>

1、首先大家在Photoshop中统筹出提醒框的样子及背景。

servlet只要回到一段字符串就足以了,就不贴了.

必威官方网站 2

. 开端测量试验暂未察觉大的BUG,总体来讲不比意的是鼠标移来移去不断触发气泡时会冒出XX为空或不是...

2、大家将背景切成八个部分,top、main、bottom

top:必威官方网站 3

main:必威官方网站 4

本文由betway必威发布于网页设计,转载请注明出处:必威官方网站:JQuery达成轻巧前卫快速的血泡提

Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。