您提供的链接似乎首先给出了背景图像的悬停状态,然后通过 timeOut 它显示了一个工具提示。我正在制作一个小提琴来说明这一点。
所以,给你。这是Fiddle!
最重要的是 jQuery,它包含延迟以及 CSS 中规定的图像的悬停状态。因此,当用户悬停图像时,他得到的第一件事就是另一张图像。这是通过简单的 CSS 悬停和 CSS sprites 完成的。
.item {
background-color: white;
width: 100%;
height: 100%;
background-repeat: no-repeat;
background-position: center top;
}
.item:hover {
background-repeat: no-repeat;
background-position: center bottom;
}
#flower {
background-image: url('http://bramvanroy.be/files/images/tooltipOverlay.jpg');
}
当图像悬停在开头时,触发了一个jQuery函数但它被延迟了:
var tooltip = $(".item-tooltip");
tooltip.hide();
$(".item-wrapper").hover(
function() {
$(this).children(tooltip).delay(550).fadeIn("slow");
$(this).children(".item").fadeOut("slow");
},
...
当鼠标离开工具提示时,它会被隐藏,.item 会再次显示:
...
function(){
$(this).children(tooltip).fadeOut("fast");
$(this).children(".item").fadeIn("fast");
}
);
改进的答案:
这里是Showcase,这里是那个展示柜的fiddle,这里是图片does not change的小提琴(如你所愿)。
我使用了 jQuery 插件 hoverIntent 来确保不是每个悬停一毫秒的图像都会显示工具提示。它的作用是检查用户是否意图悬停图像,然后(在某个 timeOut 之后)执行该功能。有关此插件的更多信息,请通过here。你可以使用jQuery的标准hover(),但我不建议这样做。
z-index 也需要更改,否则图像会出现在工具提示下方或其他项目的图像会与我们想要的图像的工具提示重叠。
如果您还有其他问题,请在 cmets 中说出来。