神风王座
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>
var speed = 0;
if(speed >Target)
{
speed = -10;
}
else
{
speed = 10;
}
判断语句错了,你都定义了speed为0,还比较什么。
应该是al与Target的比较。
个人看法,希望能帮到你
JS动画效果
113923 学习 · 1443 问题
相似问题
回答 1
回答 1