為什么鼠標(biāo)移開時(shí)沒反應(yīng)呢
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>透明度動(dòng)畫</title>
<style type="text/css">
? ? body,div{padding:0;margin:0;}
? ? #div1{
? ? ? width: 200px;height: 200px;background: red;filter:alpha(opacity:30);opacity: 0.3;
? ? }
</style>
<script>
? ? window.onload=function(){
? ? ? ? var odiv=document.getElementById('div1');
? ? ? ? odiv.onmouseover=function(){
? ? ? ? ? ? startmove(100);
? ? ? ? }
? ? ? ? odiv.onmouseout=function(){
? ? ? ? ? ? startmove(30);
? ? ? ? }
? ? }
? ? var timer=null;
? ? var alpha=30;
? ? function startmove(itaget){
? ? ? ? clearInterval('timer');
? ? ? ?var odiv=document.getElementById('div1');
? ? ? ?timer=setInterval(function(){
? ? ? ? var speed=0;
? ? ? ? if(alpha>itaget)
? ? ? ? ? ? {speed=-10;}
? ? ? ? else
? ? ? ? ? ? {speed=10;}
? ? ? ? if(alpha==itaget)
? ? ? ? ? ? {clearInterval('timer');}
? ? ? ? else
? ? ? ? ? ? {alpha+=speed;
? ? ? ? ? ? odiv.style.filter='alpha(opacity:'+alpha+')';
? ? ? ? ? ? odiv.style.opacity=alpha/100;
? ? ? ? }
? ? ? ?},30)
? ? }
</script>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
</head>
<body>
? ? <div id="div1">
? ? ? ??
? ? </div>
</body>
</html>
2016-10-16
clearInterval(timer);
這個(gè)得這么寫哦。。太不認(rèn)真看了。