2011-10-08 30 views
2

我嘗試執行以下代碼以顯示鏈接懸停時的透明度框。懸停項目時IE 8中的不透明度

<script type="text/javascript"> 
    $(document).ready(function(){ 

$(".menu a").hover(function() { 
    $(this).next("em").animate({filter:"alpha(opacity=40)", top: "75"}, "slow"); 
}, function() { 
    $(this).next("em").animate({opacity: "hide", top: "85"}, "fast"); 
}); 
    }); 
</script> 
    <style> 
    .menu li em { 
background: #000; 
width: 180px; 
height: 45px; 
position: absolute; 
top: 85px; 
left: -15px; 
text-align: center; 
padding: 20px 12px 10px; 
font-style: normal; 
z-index: 2; 
color:fff; 
display:none; 
     } 
    </style> 
     <body> 
     <ul class="menu"> 
<li> 
    <a href="http://www.example.com">This is an example</a>  
    <em>Welcome to this example tutorial</em> 
    </li> 
     </ul> 
     </body> 

當我懸停鏈接,透明不工作,什麼正確的透明代碼我需要放在那裏我的意思是在JavaScript函數內。非常感謝

+0

任何人請幫助我,謝謝 – smith

回答

0

只要嘗試使用「不透明度:0.4」和「不透明度:0」。 jQuery將這些值標準化爲在IE中「過濾」值。

$(".menu a").hover(function() { 
    $(this).next("em").animate({opacity: 0.4, top: "75"}, "slow"); 
}, function() { 
    $(this).next("em").animate({opacity: 0, top: "85"}, "fast"); 
}); 
+0

你的意思是把opacity:0.4和opacity:0放在一起嗎?如$(this).next(「em」)。animate({opacity:0.4,opacity:0,top:「30」},「slow」); – smith

+0

編輯我的評論澄清。在{object}中設置兩個同名屬性只是覆蓋第一個 - 我的意思是你應該對第一個動畫使用opacity:0.4,對第二個動畫使用opacity:0。 –

1

jquery是一個跨瀏覽器庫和過濾器:「alpha(opacity = 40)」是瀏覽器特定的。你只是使用不透明。

$(".menu a").hover(function() { 
    $(this).next("em").animate({opacity:"0.4", top: "75"}, "slow"); 
},function() { 
    $(this).next("em").animate({opacity: "0", top: "85"}, "fast"); 
}); 
});