jQuery(Sweet Titles(美妙的标题提示
上一篇: jQuery(点击链接文字后替换文字
实现步骤:
1.引入jQuery 库
2.jquery.sweetTitles.js的代码如下:
/*
Sweet Titles (c) Creative Commons 2009
http://creativecommons.org/licenses/by-nc-sa/3.0/
Author: Leeiio | http://leeiio.me
*/
/*
Something Special tipElements
Do not include href="#xxx" : a:not([href^='#'])
*/
var sweetTitles = {
x : 10, // @Number: x pixel value of current cursor position
y : 20, // @Number: y pixel value of current cursor position
tipElements : "a", // @Array: Allowable elements that can have the toolTip,split with ","
init : function() {
$(this.tipElements).mouseover(function(e){
this.myTitle = this.title;
this.myHref = this.href;
this.myHref = (this.myHref.length > 30 ? this.myHref.toString().substring(0,30)+"..." : this.myHref);
this.title = "";
var tooltip = "
"+this.myTitle+""+this.myHref+""+"
";
$('body').append(tooltip);
$('#tooltip')
.css({
"opacity":"0.8",
"top":(e.pageY+20)+"px",
"left":(e.pageX+10)+"px"
}).show('fast');
}).mouseout(function(){
this.title = this.myTitle;
$('#tooltip').remove();
}).mousemove(function(e){
$('#tooltip')
.css({
"top":(e.pageY+20)+"px",
"left":(e.pageX+10)+"px"
});
});
}
};
$(function(){
sweetTitles.init();
});
CSS代码:
body div#tooltip { position:absolute;z-index:1000;max-width:220px;width:auto !important;width:220px;background:#000;text-align:left;padding:5px;min-height:1em;}
body div#tooltip p { margin:0;padding:0;color:#fff;font:12px verdana,arial,sans-serif; }
body div#tooltip p em { display:block;margin-top:3px;color:#f60;font-style:normal;font-weight:bold; }
若要整成圆角的提示,Hack一下即可:
body div.tooltip{-moz-border-radius:5px;-khtml-border-radius: 5px;-webkit-border-radius: 5px;}

Google Chrome 6.0.483.0
Windows XP
2010/08/22 9:56 上午 on 1这个效果不太好,有些东西会被这东西遮住
Internet Explorer 6.0
Windows XP
2010/04/13 8:35 下午 on 1太长链接就不显示了,再说状态栏有地址显示,拖个尾巴像彗星~
Google Chrome 4.1.249.1045
Windows XP
2010/04/13 9:13 下午 on 2@thinknew 呵呵…淡定…Chrome木有状态栏…链接显示的最大长度在代码里限定了…所以有省略号…其实这效果在火狐下最好看了..
Google Chrome 5.0.366.2
Windows XP
2010/04/03 8:43 下午 on 1这个效果我上次给去掉了,觉得没什么用。
Google Chrome 4.1.249.1042
Windows XP
2010/04/03 9:10 下午 on 2@阿修
我先体验体验再去掉…