注意:我通过 Firebug 构建并测试了我的解决方案,以处理您提供的链接。如果您按顺序执行这些步骤,您应该让它完全正常工作
除了在 Safari 和 Firefox 3.5 以及其他支持 RGBA 背景颜色的浏览器中,您将无法从颜色动画transparent
到颜色。如果您正在寻找跨浏览器支持,那么我会这样解决问题:
1.让您的默认悬停效果由非 js 类限定,因此:hover
效果将作为后备。一个很好的方法如下:
<html class="no-js">
<head>
.... meta, title, link tags ...
<script type="text/javascript">document.documentElement.className = "js";</script>
.... other scripts ...
</head>
这甚至在页面显示之前no-js
更改。js
2.a
使用 jQuery 在标签旁边添加虚拟元素(js
添加虚拟元素在步骤 3 中)
这是要使用的CSS:
.js .iconrow { background: none !important } /* Hide current hover effect */
.iconfader {
position: absolute;
display: block;
left: 0;
top: 0;
width: 100%;
height: 100%;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
background-color: #ccc;
z-index: 5;
}
.iconrow { position: relative } /* Spans are absolute, need the parent to be relative */
.iconrow a { position: relative; z-index: 10} /* Needs to sit on top */
3.淡入淡出新的虚拟mouseenter
元素mouseleave
$('.iconrow').each(function(){
var $span = $("<span class='iconfader'></span>").css('opacity',0.0).appendTo(this);
$(this).hover(function(){
$span.stop().animate({opacity: 0.8}, 200);
}, function(){
$span.stop().animate({opacity: 0.0}, 200);
});
});
最后,如果您决定使用图像背景而不是纯色,请小心。IE7 和 IE8 无法更改 24 位 PNG 文件的不透明度。它完全搞砸了透明度。