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
舉報
2016-07-26
要把_animate()里面的參數刪了,因為你在這個函數外面以及有個ball了。
2016-09-27
如果你問的是promise改寫之前的話,是因為你的body還沒加載就加載了js, 所以提示undefined
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()
? ?})
}
2016-07-24
一般通過非id和querySelect獲得的dom元素都是一個數組,要加下標比如ball[0]來調用對象的屬性
2016-07-24
你看一下你的ball是不是個數組