当前位置: 编程技术>jquery
jquery半透明tip提示效果
来源: 互联网 发布时间:2014-10-07
本文导语: 例子,一个半透明的tooltip组件。 代码示例: (function($){ jQuery.fn.extend({ showTip:function(settings) { var defaultOptions = {tipInfo:$(this).attr("title"), isAnimate:false}; ...
例子,一个半透明的tooltip组件。
代码示例:
(function($){
jQuery.fn.extend({
showTip:function(settings)
{
var defaultOptions = {tipInfo:$(this).attr("title"), isAnimate:false};
var panel = '
$(this).each(function(){
//初始化配置信息,与运算
var options = jQuery.extend(defaultOptions,settings);
if(!options.tipInfo)
{
return;
}
$(this).removeAttr("title");
$(this).mouseover(function(){
//设置提示信息最小宽度为163
var oToolTip = $(panel);
$(oToolTip).find('.ctn').append(options.tipInfo);
//添加淡入效果
if(options.isAnimate)
{
$(oToolTip).fadeIn("slow");
} else{
$(oToolTip).show();
}
$(this).after(oToolTip);
//计算提示信息的top、left和width
var position = $(this).position();
var width = $(this).width();
var oTipTop = position.top;
var oTipLeft = position.left + width +5;
$(oToolTip).css("top" , oTipTop + "px").css("left" , oTipLeft + "px");
$(this).mouseout(function(){
$(oToolTip).remove();
});
});
});
return this;
}
})
})(jQuery);
jQuery.fn.extend({
showTip:function(settings)
{
var defaultOptions = {tipInfo:$(this).attr("title"), isAnimate:false};
var panel = '
' +
''+
'
'
'; ''+
'
'+
'
'' +
'
'+ '
' +
'' +
'
' + '' +
'
'' +
'
'
$(this).each(function(){
//初始化配置信息,与运算
var options = jQuery.extend(defaultOptions,settings);
if(!options.tipInfo)
{
return;
}
$(this).removeAttr("title");
$(this).mouseover(function(){
//设置提示信息最小宽度为163
var oToolTip = $(panel);
$(oToolTip).find('.ctn').append(options.tipInfo);
//添加淡入效果
if(options.isAnimate)
{
$(oToolTip).fadeIn("slow");
} else{
$(oToolTip).show();
}
$(this).after(oToolTip);
//计算提示信息的top、left和width
var position = $(this).position();
var width = $(this).width();
var oTipTop = position.top;
var oTipLeft = position.left + width +5;
$(oToolTip).css("top" , oTipTop + "px").css("left" , oTipLeft + "px");
$(this).mouseout(function(){
$(oToolTip).remove();
});
});
});
return this;
}
})
})(jQuery);
2,css代码
代码示例:
.chart-panel {
Z-INDEX: 99999;
LEFT: 0%;
MARGIN-LEFT: 0px;
ZOOM: 1;
POSITION: absolute;
TOP: 20%;
Display: none
}
.chart-spanBG {
background-color: #FFFFCC;
POSITION: absolute;
FILTER: alpha(opacity:50);
opacity: 0.50;
width: 100%;
height: 100%
}
.chart-span {
width: auto;
height: auto;
margin: auto;
POSITION: relative
}
.chart-panel .container {
Z-INDEX: 2;
BORDER-RIGHT: #999 1px solid;
BORDER-TOP: #999 1px solid;
MARGIN: 0px;
OVERFLOW: hidden;
BORDER-LEFT: #999 1px solid;
BORDER-BOTTOM: #999 1px solid;
POSITION: relative
}
.chart-panel .shadow {
Z-INDEX: 1;
width:100%;
height:100%;
POSITION: absolute;
TOP: 0px;
LEFT: 0px
}
.chart-panel H5 {
FONT-WEIGHT: normal;
font-size:10px;
margin: 3px;
white-space:nowrap;
font-family: Verdana, Arial, Helvetica, sans-serif;
color:#000000;
}
.chart-panel .ctn {
BACKGROUND: Transparent;
}
Z-INDEX: 99999;
LEFT: 0%;
MARGIN-LEFT: 0px;
ZOOM: 1;
POSITION: absolute;
TOP: 20%;
Display: none
}
.chart-spanBG {
background-color: #FFFFCC;
POSITION: absolute;
FILTER: alpha(opacity:50);
opacity: 0.50;
width: 100%;
height: 100%
}
.chart-span {
width: auto;
height: auto;
margin: auto;
POSITION: relative
}
.chart-panel .container {
Z-INDEX: 2;
BORDER-RIGHT: #999 1px solid;
BORDER-TOP: #999 1px solid;
MARGIN: 0px;
OVERFLOW: hidden;
BORDER-LEFT: #999 1px solid;
BORDER-BOTTOM: #999 1px solid;
POSITION: relative
}
.chart-panel .shadow {
Z-INDEX: 1;
width:100%;
height:100%;
POSITION: absolute;
TOP: 0px;
LEFT: 0px
}
.chart-panel H5 {
FONT-WEIGHT: normal;
font-size:10px;
margin: 3px;
white-space:nowrap;
font-family: Verdana, Arial, Helvetica, sans-serif;
color:#000000;
}
.chart-panel .ctn {
BACKGROUND: Transparent;
}
3,html代码部分
代码示例:
无标题页
$(document).ready(function(){
//所有的Input同意添加tooltip
var content1 = {
tipInfo: "Information tipsThis is the information,it is semitransparent"
};
var content2 = {
tipInfo: "Information tipsThis is the information,it is semitransparent",
isAnimate: true
};
$("#URLTest").showTip(content1);
$("#m").showTip(content2);
});
URLTest
效果图,如下: