求帮我看看 鼠标移出没反应 问题出哪里了?

来源:2-2 JS透明度动画

神风王座

2015-08-28 20:12

<!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">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>透明度的改变 </title>

<style type="text/css">

*{

margin:0px; padding:0px;

}

#box{

width:300px;

height:250px;

filter:alpha(opacity=:30);

opacity:0.3;

background:red;

}

</style>

<script>

window.onload = function()

{

var Obox = document.getElementById("box");

Obox.onmouseover = function()

{

startcharge(100);

}

Obox.onmouseout = function()

{

startcharge(30);

}

var timer = null;

var al = 30;

function startcharge(Target)

{

clearInterval(timer);

var Obox = document.getElementById("box"); 

timer =setInterval(function(){

var speed = 0;

if(speed >Target)

{

speed = -10;

}

else

{

speed = 10;

}

if( al ==Target)

{

clearInterval(timer);

}

else

{

al+=speed;

Obox.style.opacity = al/100;

Obox.style.filter = "alpha(opacity:"+alpha+")";

}

},30)

}

}


</script>


</head>


<body>

<div id="box"></div>

</body>

</html>


写回答 关注

1回答

  • The_Legend
    2015-08-30 07:20:40

    var speed = 0;

    if(speed >Target)

    {

    speed = -10;

    }

    else

    {

    speed = 10;

    }

    判断语句错了,你都定义了speed为0,还比较什么。

    应该是al与Target的比较。

    个人看法,希望能帮到你


JS动画效果

通过本课程JS动画的学习,从简单动画开始,逐步深入各种动画框架封装

113931 学习 · 1443 问题

查看课程

相似问题