为了账号安全,请及时绑定邮箱和手机立即绑定

没效果,大神帮看看啥问题,chrome浏览器报错是13行,Uncaught TypeError:Cannot set property 'onmouseover' of null

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>透明度</title>
<style type="text/css">
	*{margin: 0;padding: 0;}
	#box1{width: 200px;height: 200px;background: red;filter: alpha(opacity:30);opacity: 0.3;}
</style>
<script type="text/javascript">
	window.onload=function(){
		var v=document.getElementById('div1');
		v.onmouseover=function(){
			star(100);
		}
		v.onmouseout=function(){
			star(30);
		}
	}
	var timer=null;
	var alpha=30;
	function star(iTarget){
        var v=document.getElementById('div1');
    clearInterval(timer);
    timer=setInterval(function(){
    	var speed=0;
    	if(alpha>iTarget){
    		speed=-10;
    	}else{
    		speed=10;
    	}
     if(alpha==iTarget){
     	clearInterval(timer);
     }else{
      alpha=alpha+speed;
      v.style.filter='alpha(opacity:'+alpha+')'
      v.style.opacity=alpha/100;
     }
    },30)
	}
</script>
</head>
<body>
<div id="box1"></div>
</body>
</html>


正在回答

1 回答

你的id定义为box1,但是你上面在getElementById('div1')的时候都写成了div1

0 回复 有任何疑惑可以回复我~
#1

名字只是个代号丶 提问者

非常感谢!
2016-08-03 回复 有任何疑惑可以回复我~
#2

kx00012kx

请教一下大神: oDiv.style.filter='alpha(opacity:'+alpha+')';在这一行里的“+alpha+”,alpha前后各有一个加号,他们分别代表了什么意思啊?
2016-08-08 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

没效果,大神帮看看啥问题,chrome浏览器报错是13行,Uncaught TypeError:Cannot set property 'onmouseover' of null

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信