我使用下面的JQuery脚本创建悬停工具提示,问题是如果工具提示接近屏幕边缘,它不会翻转或对齐边缘。修改JQuery easyTooltip来检测屏幕边缘
(function($) {
$.fn.easyTooltip = function(options){
var defaults = { // default configuration properties
xOffset: 10,
yOffset: 25,
tooltipId: "easyTooltip",
clickRemove: false,
content: "",
useElement: ""
};
var options = $.extend(defaults, options);
var content;
var url;
this.each(function() {
var title = $(this).attr("title");
var url = $(this).attr("tooltipURL");
$(this).hover(function(e){
if (url != "" && url != undefined) {
content = '<span class="loadingimage"></span> Loading...';
tooltip(content);
$('#'+options.tooltipId).load(url, {"id":$(this).attr("value")});
} else {
content = (options.content != "") ? options.content : title;
content = (options.useElement != "") ? $("#" + options.useElement).html() : content;
$(this).attr("title","");
if (content != "" && content != undefined){
tooltip(content);
}
}
function tooltip(content) {
$("body").append("<div id='"+ options.tooltipId +"'>"+ content +"</div>");
$("#" + options.tooltipId)
.css("position","absolute")
.css("top",(e.pageY - options.yOffset) + "px")
.css("left",(e.pageX + options.xOffset) + "px")
.css("display","none")
.fadeIn("fast")
}
},
function(){
$("#" + options.tooltipId).remove();
$(this).attr("title",title);
});
$(this).mousemove(function(e){
$("#" + options.tooltipId)
.css("top",(e.pageY - options.yOffset) + "px")
.css("left",(e.pageX + options.xOffset) + "px")
});
if(options.clickRemove){
$(this).mousedown(function(e){
$("#" + options.tooltipId).remove();
$(this).attr("title",title);
});
}
});
};
})(jQuery);
的http://文档.jquery.com /插件/工具提示 – kennytm 2010-09-12 07:57:08
可以显示您的工作页面吗? – 2010-09-12 08:02:13
它正在一个新网站上使用,我正在使用http://webcomictweets.com/将鼠标悬停在任何头像或用户名上作为示例。 – Canadaka 2010-09-13 11:31:06