以下是来自webdesign tuts+的工具提示脚本。很好的工作,但它不能禁用默认的工具提示。编辑jquery工具提示脚本以禁用默认工具提示
我缺乏相应更新此脚本的技能。我非常感谢编辑,将禁用默认工具提示!
谢谢。
<script type="text/javascript">
$("a").mouseenter(function (e) { //event fired when mouse cursor enters "a" element
var $class_name = $(this).attr("class").slice(13); //get class attribute of "a" element after leaving 13 characters which is equal to "tooltip_link "
var $x = e.pageX - this.offsetLeft; //get mouse X coordinate relative to "a" element
var $tooltip_text = $(this).attr("title"); //get title attribute of "a" element
if ($tooltip_text.length > 0) { //display tooltip only if it has more than zero characters
$(this).append('<div class="tooltip ' + $class_name + '">' + $tooltip_text + '</div>'); //append tooltip markup, insert class name and tooltip title from the values above
$("a > div.tooltip.center").css("left", "" + $x - 103 + "px"); //set tooltip position from left
$("a > div.tooltip.left").css("left", "" + $x + "px"); //set tooltip position from left
$("a > div.tooltip.right").css("left", "" + $x - 208 + "px"); //set tooltip position from left
$("a > div.tooltip." + $class_name).fadeIn(300); //display, animate and fade in the tooltip
}
});
$("a").mouseleave(function() { //event fired when mouse cursor leaves "a" element
var $class_name = $(this).attr("class").slice(13); //get class attribute of "a" element after leaving 13 characters which is equal to "tooltip_link "
//fade out the tooltip, delay for 300ms and then remove the tooltip and end the custom queue
$("a > div.tooltip." + $class_name).fadeOut(300).delay(300).queue(function() {
$(this).remove();
$(this).dequeue();
});
});
</script>
grc,这简直太棒了。非常感谢!但是,只是一个说明。您的编辑会禁用所有默认工具提示,而不仅仅是具有“工具提示”类别的工具提示。在不使用新工具提示的情况下,如何保持默认工具提示处于活动状态?不知道它是否意味着什么,但在html中使用的实际类是“tooltip_link”。 – user705100
好吧,我已经更新了代码和示例,以便在删除工具提示之前检查该类是否为“tooltip_link”。 – grc
奇怪的是,默认工具提示在链接是图像的位置仍然不起作用。尽管如此,还是比原来有所改进。再次感谢。 – user705100