为什么speed直接用小数不可以,只能用整数,speed/100才可以,用小数判断出错????
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style type="text/css">
#one{
width:200px;
height:200px;
opacity: 0.3;
background: red;
}
</style>
<script type="text/javascript">
window.onload=function(){
var one=document.getElementById("one");
one.onmouseover=function(){
startMove(1);
}
one.onmouseout=function(){
startMove(0.3);
}
}
var timer=null;
var alpha=0.3;
function startMove(target){
var one=document.getElementById("one");
clearInterval(timer);
var speed=0;
if(alpha>target){
speed=-0.1;
}else{
speed=0.1;
}
timer=setInterval(function(){
if(alpha==target){
clearInterval(timer);
}
else{
alpha+=speed;
one.style.opacity=alpha;
}
},30);
}
</script>
<body>
<div id="one"></div>
</body>
</html>