帮我看看这个js代码为什么没反应吧
!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title></title><style>div{heig...
!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
div{height: 200px;width: 200px;margin: 20px;background: palevioletred;float:left;filter:alpha(opacity:30);opacity: 0.3;}
</style>
<script>
window.onload=function()
{
var alpha=30;
var aDiv=document.getElementsByTagName('div');
for(var i=0;i<aDiv.length;i++){
aDiv[i].timer=null;
aDiv[i].onmouseover=function()
{
startMove(this,100)
};
aDiv[i].onmouseout=function()
{
startMove(this,30)
}
}
function startMove(obj,iTarget)
{
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=(iTarget-alpha)/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(alpha==iTarget){clearInterval(obj.timer)}
else
{
alpha+=speed;
aDiv.style.filter='alpha(opacity:'+alpha+')';
aDiv.style.opacity=alpha/100;
}
},30)
}
}
</script>
</head>
<body>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
</html> 展开
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
div{height: 200px;width: 200px;margin: 20px;background: palevioletred;float:left;filter:alpha(opacity:30);opacity: 0.3;}
</style>
<script>
window.onload=function()
{
var alpha=30;
var aDiv=document.getElementsByTagName('div');
for(var i=0;i<aDiv.length;i++){
aDiv[i].timer=null;
aDiv[i].onmouseover=function()
{
startMove(this,100)
};
aDiv[i].onmouseout=function()
{
startMove(this,30)
}
}
function startMove(obj,iTarget)
{
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=(iTarget-alpha)/6;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(alpha==iTarget){clearInterval(obj.timer)}
else
{
alpha+=speed;
aDiv.style.filter='alpha(opacity:'+alpha+')';
aDiv.style.opacity=alpha/100;
}
},30)
}
}
</script>
</head>
<body>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询