我创建的社交网络按钮,其中有一个JavaScript函数,创建一个效果灯泡慢点火,覆盖了css悬停。它的工作,但在IE7没有。奇怪的是'IE调试'不报告错误。您可以在此链接上看到http://www.matteowebdesigner.com/test/yesimove/涵盖的效果不工作ie7
代码解释:
<!-- html -->
<div class="social">
<a href="http://www.facebook.com/yesimove" class="facebook" rel="external">facebook</a>
<a href="https://twitter.com/yesimove" class="twitter" rel="external">twitter</a>
<a href="#" class="google" rel="external">google</a>
</div>
一些CSS即时悬停效果。
#footer .social .facebook,
#footer .social .facebook .fade {background-position:-80px -90px;}
#footer .social .twitter,
#footer .social .twitter .fade {background-position:-107px -90px;}
#footer .social .google,
#footer .social .google .fade{background-position:-134px -90px;}
/*hover*/
#footer .social .facebook:hover {background-position:-80px -117px;}
#footer .social .twitter:hover {background-position:-107px -117px;}
#footer .social .google:hover {background-position:-134px -117px;}
该代码在创建两个跨度用于覆盖的背景和一个元件:悬停的CSS。然后在第二跨度它隐藏与礼不透明度:0然后用不透明的onmouseover将成为1
/*= socialOver =*/
function socialOver(){
var socials = $('#footer .social a');
$('<span class="fade"></span><span class="fade"></span>').appendTo(socials);
socials.each(function(i,o){
var bpx = $(o).css('backgroundPositionX');
$(o).find('.fade:eq(1)').css({
backgroundPosition:bpx+' -117px',
opacity:0
});
});
socials.find('.fade').on('mouseover',function(e){
$(this).stop(true,true).animate({
'opacity':'1'
},300);
}).on('mouseout',function(e){
$(this).stop(true,true).animate({
'opacity':'0'
},600);
});
};
我发现在页面顶部添加<!DOCTYPE html>使得它更有可能在IE中正确显示CSS。 – Matthias 2012-07-30 13:12:01
为什么你自己动画不透明而不是使用jQuery的'fadeIn'方法? – Blazemonger 2012-07-30 13:12:32
但我的doctype是identic,它是<!DOCTYPE html>。 – 2012-07-30 13:14:18