style.marginLeft 报错Cannot read property 'style' of undefined
var marginLeft = parseInt(ball.style.marginLeft,10)
这行报错,Cannot read property 'style' of undefined
是不是style.marginLeft这个写法有问题呢?
var marginLeft = parseInt(ball.style.marginLeft,10)
这行报错,Cannot read property 'style' of undefined
是不是style.marginLeft这个写法有问题呢?
2016-07-24
var Promise = window.Promise
function promiseAnimate(ball,distance){
return new Promise(function(resolve,reject){
function _animate(ball,distance,cb){
setTimeout(function () {
var marginLeft = parseInt(ball.style.marginLeft,10)
if(marginLeft === distance){
resolve()
}else{
if(marginLeft < distance){
marginLeft++
}else{
marginLeft--
}
ball.style.marginLeft = marginLeft + 'px'
_animate()
}
},13)
}
_animate()
})
}
举报