http://stackoverflow.com/questions/6065169/requestanimationframe-with-this-keyword

Observe that you call obj.draw as :ide

<button onclick="obj.draw()

The first time obj.draw is called, the context is different than when it called by requestAnimationFramemultiple times, as a callback function before the repaint.this

So try by saving this in a variable which is outside the scope of the callback function.spa

Something like :.net

var obj = { //... draw: function () { var sender = this; var draw = function () { document.getElementById(sender.id).style.left = (sender.speed++) + 'px'; window.requestAnimationFrame(draw); } draw(); } }

Here is an updated demo of how this would look like.code

http://stackoverflow.com/questions/6065169/requestanimationframe-with-this-keywordip

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息