javascript获取css中的样式值

     <body>
<input type="button" id="btn" value="启动"/>
<img src="timg.jpg" id="img" alt="" />
<script type="text/javascript"> window.onload = function()
{
var time = null;
var img = document.getElementById("img"); img.onmouseover = function()
{
startMove(img,100,10); //alert(getComputedStyle(img,false).opacity) }
img.onmouseout = function()
{
startMove(img,30,-10);
} function startMove(obj,iTarget,ispeed)
{
var icur =0;
clearInterval(time);
time = setInterval(function(){
icur = Math.round((getComputedStyle(img,false).opacity)*100); //为什么不能获取到呢
if(icur == iTarget)
{
clearInterval(time);
}else{
obj.style.opacity = (icur + ispeed)/100 ;
obj.style.filter = 'alpha(opacity = '+(icur + ispeed)+')';
}
},30)
}
} </script>
</body>

注意 ie下不支持  

getComputedStyle
上一篇:SpringMVC配置


下一篇:201521123094 《Java程序设计》第1周学习总结