Javascript的小问题 淡入效果
<!doctypehtml><html><head><metacharset="UTF-8"><title>ÎÞ±êÌâÎ...
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>ÎÞ±êÌâÎĵµ</title>
<style>
#div1{width:200px; height:200px; background:#EB1A1E; filter:alpha(opacity:30); opacity:0.3; position:absolute;}
</style>
<script>
window.onload=function () {
var timer=null;
var alpha=30;
function startMove(q)
{
var oDiv=document.getElementById('div1');
var speed=0;
clearInterval(timer);
timer=setInterval(function ()
{
if(alpha<q)
{
speed=10;
}
if(alpha>q)
{
speed=-10;
}
if(alpha==q)
{
clearInterval(timer);
}
else
{
alpha+=speed;
oDiv.style.filter='alpha(opacity:'+alpha+')'
oDiv.style.opacity=alpha/100
}
},30)
}
};
</script>
</head>
<body>
<input type="button" value="an" id="we" onClick="startMove(100)">
<div id="div1"></div>
<br>
</body>
</html>
程序运行不起。。 展开
<html>
<head>
<meta charset="UTF-8">
<title>ÎÞ±êÌâÎĵµ</title>
<style>
#div1{width:200px; height:200px; background:#EB1A1E; filter:alpha(opacity:30); opacity:0.3; position:absolute;}
</style>
<script>
window.onload=function () {
var timer=null;
var alpha=30;
function startMove(q)
{
var oDiv=document.getElementById('div1');
var speed=0;
clearInterval(timer);
timer=setInterval(function ()
{
if(alpha<q)
{
speed=10;
}
if(alpha>q)
{
speed=-10;
}
if(alpha==q)
{
clearInterval(timer);
}
else
{
alpha+=speed;
oDiv.style.filter='alpha(opacity:'+alpha+')'
oDiv.style.opacity=alpha/100
}
},30)
}
};
</script>
</head>
<body>
<input type="button" value="an" id="we" onClick="startMove(100)">
<div id="div1"></div>
<br>
</body>
</html>
程序运行不起。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询