根本停不下的龙
2018-12-21 11:14
错误:
1.html:34 Uncaught TypeError: Cannot set property 'onmouseover' of null
at window.onload (1.html:34)
原代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css" media="screen">
*{
padding: 0;
margin: 0;
}
.dv1{
margin-top: 20px;
width: 200px;
height: 200px;
background-color: red;
margin-left: -200px;
position: relative;
}
.dv2{
margin-top: 85px;
width: 50px;
height: 50px;
background-color: gold;
position: absolute;
left: 200px;
}
</style>
</head>
<body>
<div class="dv1"><span class="dv2">ghcvn </span></div>
<script type="text/javascript" charset="utf-8" async defer>
window.onload = function(){
var dObj = document.getElementById("dv1");
dObj.onmouseover = function(){
startMove();
}
}
function startMove(){
var dObj = document.getElementById("dv1");
setInterval(function(){
dObj.style.left = dObj.offsetLeft+10+"px";
},30)
}
</script>
</body>
</html>
没传参数
JS动画效果
113925 学习 · 1443 问题
相似问题