注意:我通过 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.使用jQuery在a标签旁边添加虚拟元素(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 文件的不透明度。它完全搞砸了透明度。