我創建的社交網絡按鈕,其中有一個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