为什么把margin-left写在css里就不能用ball.style.marginLeft了?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Promise</title>
<style>
.ball{width:40px;height: 40px;border-radius: 50%; margin-left: 0px;}
.ball1{background: red;margin-left: 0px;}
.ball2{background: green;}
.ball3{background: blue;}
</style>
</head>
<body>
<div class="ball ball1" ></div>
<div class="ball ball2" ></div>
<div class="ball ball3" ></div>
<script>
var ball1 = document.querySelector('.ball1');
var ball2 = document.querySelector('.ball2');
var ball2 = document.querySelector('.ball3');
function ani(ball,distance,cb){
setTimeout(function(){
var marle = parseInt(ball.style.marginLeft,10);
if(marle === distance){
cb && cb();
}else{
if(marle < distance){
marle ++ ;
}else{
marle -- ;
}
ball.style.marginLeft = marle + "px";
ani(ball,distance,cb)
}
},13)
}
//ani(ball1,100,function(){})
</script>
</body>
</html>
如果 这样写 而不是写行内 就无法用var marle = parseInt(ball.style.marginLeft,10); 这是为什么