style.marginLeft 報(bào)錯(cuò)Cannot read property 'style' of undefined
var marginLeft = parseInt(ball.style.marginLeft,10)?
這行報(bào)錯(cuò),Cannot read property 'style' of undefined?
是不是style.marginLeft這個(gè)寫法有問(wèn)題呢?
var marginLeft = parseInt(ball.style.marginLeft,10)?
這行報(bào)錯(cuò),Cannot read property 'style' of undefined?
是不是style.marginLeft這個(gè)寫法有問(wèn)題呢?
2016-07-24
舉報(bào)
2016-07-26
要把_animate()里面的參數(shù)刪了,因?yàn)槟阍谶@個(gè)函數(shù)外面以及有個(gè)ball了。
2016-09-27
如果你問(wèn)的是promise改寫之前的話,是因?yàn)槟愕腷ody還沒(méi)加載就加載了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
一般通過(guò)非id和querySelect獲得的dom元素都是一個(gè)數(shù)組,要加下標(biāo)比如ball[0]來(lái)調(diào)用對(duì)象的屬性
2016-07-24
你看一下你的ball是不是個(gè)數(shù)組