解析 'left' 的值時出錯。 聲明被丟棄。
html文件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
?? ?<title>動畫</title>
?? ?<link rel="stylesheet" type="text/css" href="css/style.css">
?? ?<script type="text/javascript" src="js/script.js"></script>
</head>
<body>
? <div id="box">
? ?? ?123
? </div>
</body>
</html>
css文件
*{
?? ?margin: 0;
?? ?padding-top: 0;
}
#box{
?? ?width: 200px;
?? ?height: 200px;
?? ?left:-200px;
?? ?background: #567;
?? ?cursor: pointer;
}
js文件
var timer=null;
window.onload=function(){
?? ?var box=document.getElementById('box');
?? ?box.onmouseover =function(){
?? ??? ?startMove();
?? ?}
}
function startMove(){
?? ?setInterval(function(){
?? ??? ?box.style.left=box.left+10+'px';
?? ?},30);
}
2016-11-19
把倒數(shù)第三行的 box.left去掉