能帮我看下我的代码吗, 会出现小数不精确的现象,好着急求问
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>js透明度动画</title>
<style type="text/css">
body{
margin:0px;
}
#div1{
width:200px;
height: 200px;
opacity: 0.3;
/* filter:alpha(opacity:30); */
background: red;
}
</style>
<script type="text/javascript">
window.onload=function(){
var odiv=document.getElementById("div1");
odiv.onmouseover=function(){
startmove(1);
}
odiv.onmouseout=function(){
startmove(0.3);
}
}
var timer=null;
var alpha=0.3
function startmove(iTarget){
var odiv=document.getElementById("div1");
clearInterval(timer);
timer=setInterval(function(){
var speed=0;
if (alpha>iTarget) {
speed=-0.1;
}
else{
speed=0.1;
}
if(alpha==iTarget){
clearInterval(timer);
}
else{
alpha+=speed;
/*odiv.style.filter='alpha(opacity:'+alpha+')'*/
odiv.style.opacity=alpha;
}
},30)
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>