问答详情
源自:2-2 JS透明度动画

为什么运行不了

//问什么运行不了

<!doctype html>

<html>

<head>

<meta charset="UTF-8">

<title>Untitled Document</title>

<style>

*{margin:0;padding:0}

#odiv{

width:200px;

height:200px;

left:0;

top:0;

position:relative;

opacity:0.1;

background:red;

filter:alpha(opacity:30);

opacity:0.3;

}

</style>

<script>

window.onload=function(){

var odiv=document.getElementById('odiv');

odiv.onmouseover=function(){

change(100);

}

odiv.onmouseout=function(){

change(10);

}

}    

var timer=null;

var alph=30;

function change(target){

var odiv=document.getElementById('odiv');

clearInterval(timer);

var speed=10;

        timer=setInterval(funcition(){

if(alph>target){

speed=-10;

}else{

speed=10;

}

if(alph==target){

clearInterval(timer);

}

else{

alph=alph+speed;

odiv.style.filter='alpha(opacity:'+alph+')';

odiv.style.opacity=alph/100;

}

},50);

}

</script>

</head>

<body>

<div id="odiv"></div>

</body>

</html>


提问者:漩涡鸣人007 2016-03-28 19:33

个回答

  • qq__2587
    2016-03-28 20:19:39
    已采纳

    你的timer = setInterval里面的单词 function 打错了

    朋友 敲代码的时候 注意啊!!