【发布时间】:2012-10-12 12:13:03
【问题描述】:
this page(底部的小图标)上有一些按钮,我正在使用一些 css 过渡来更改其背景。但图标第一次悬停时有闪烁!我尝试实施this thread 上提供的建议,但无济于事。有没有人知道如何在没有闪烁的情况下完成这项工作?
非常感谢!
【问题讨论】:
标签: html css css-transitions
this page(底部的小图标)上有一些按钮,我正在使用一些 css 过渡来更改其背景。但图标第一次悬停时有闪烁!我尝试实施this thread 上提供的建议,但无济于事。有没有人知道如何在没有闪烁的情况下完成这项工作?
非常感谢!
【问题讨论】:
标签: html css css-transitions
由于没有提供最小的测试用例,我可以假设您的图像需要预先加载,并且过渡与问题无关。
可以通过将背景图像指定为元素正常(非悬停)状态的背景,并添加带有负值的background-position 以使背景图像在正常状态下不可见来预加载。
例如:
/* Image is supposed to have height less than 100px here. */
A {
background: url(example.png) 0 -100px no-repeat;
}
A:hover {
background-position: 0 0;
}
顺便说一句,将两种状态(正常和悬停)的图像放到一个物理图像文件中,然后在悬停时更改 background-position 是一种惯例:
/* "rollover-sprite.png" file contains images for both states side by side. */
A {
background: url(rollover-sprite.png) no-repeat;
}
/* Width of image for each state is supposed to be 100px here
(sprite will be ~200px wide). */
A:hover {
background-position: -100px 0;
}
【讨论】:
background: url../images/mail_button_hover.png) 0 -100px no-repeat; background:url(../images/mail_button.png) no-repeat 0px 0px; 作为预加载图像的一种方式?...这似乎不起作用..我一定做错了什么。
SPAN 元素和 display: block 用于此目的。
您需要预加载要切换到的图像,“闪烁”是指悬停和实际加载图像之间的短暂延迟。有很多方法可以做到这一点,你用的是jQuery吗?
【讨论】: