我需要帮助使用jQuery ui位置查看基本工具提示。 jQuery工具提示从链接中获取title属性,并在该链接的悬停时创建工具提示。如何改进和提高代码效率?我想在这里发布这个希望它能帮助别人。我确实在我认为简单的事情上花了足够的时间。
这是我的代码(希望人们发布替代版本):
$(".tip a").hover(
function() {
var tipText = $(this).attr("title");
$("<div class='toolTip' style='display:none;'>" + tipText + " </div>").insertAfter(this);
$('.toolTip').position({
my: "left top",
at: "right top",
of: this,
collision: "flip"
});
//Is there a better way to select the tooltip?
$(this).next().fadeIn(500); //should I fade it in this way?
}, function() {
//Should I use a better selector?
$(this).next().fadeOut('slow', function() {
$(this).remove();
});
});
想法,想法,评论?谢谢大家,我希望这对其他人也有帮助!
答案 0 :(得分:1)
使用jQueryUI position()方法取决于你是否已在页面中使用jQueryUI。如果您需要的只是位置,那将是一种浪费。
使用带有offet()方法的链接偏移量和使用width()方法调整宽度来计算位置并不需要太多额外的工作。
如果已经加载了jQueryUI ... position()是一个非常方便的实用方法并且自己保存了自己的计算
编辑:使用UI位置“翻转”选项确实需要更多的努力来编码自己