现在位置:
首页 >
代码分享
>
js 重写美化title tips提示 更加美观
js 重写美化title tips提示 更加美观
//标题提示效果处
var sweetTitles = {
x: 10,
y: 20,
tipElements: "a",
init: function () {
$(this.tipElements).unbind("mouseover mouseout mousemove"); //移除之前绑定的时间防止冲突
$('#tooltip').remove(); //pjax后防止提示未消失
$(this.tipElements).mouseover(function (e) {
this.myTitle = this.title;
this.myHref = this.href;
this.myHref = (this.myHref.length > 200 ? this.myHref.toString().substring(0, 200) + "..." : this.myHref);
this.title = "";
var tooltip = "";
if (this.myTitle == "") {
tooltip = "";
}
else {
tooltip = "<div id='tooltip'><p>" + this.myTitle + "</p></div>";
$('body').append(tooltip);
$('#tooltip')
.css({
"opacity": "0.9",
"top": (e.pageY + 20) + "px",
"left": (e.pageX + 10) + "px"
}).show('fast');
}
}).mouseout(function () {
if (this.myTitle != "") {
this.title = this.myTitle;
$('#tooltip').remove();
}
}).mousemove(function (e) {
if (this.myTitle != "") {
$('#tooltip')
.css({
"top": (e.pageY + 20) + "px",
"left": (e.pageX + 10) + "px"
});
}
});
}
};
$(function () {
sweetTitles.init(); //初始化
});
sweetTitles.init(); //pjax回调
/*tips*/
.tooltip{font-size:12px;position:absolute;padding:5px;z-index:100000;opacity:.8;font-family:Microsoft Yahei}.tipsy-arrow{position:absolute;width:0;height:0;line-height:0;border:6px dashed #000;top:0;left:20%;margin-left:-5px;border-bottom-style:solid;border-top:0;border-left-color:transparent;border-right-color:transparent}.tipsy-arrow-n{border-bottom-color:#8aa653}.tipsy-inner{background-color:#8aa653;color:#FFF;max-width:200px;padding:5px 8px 4px 8px;text-align:center;border-radius:3px}