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

相关文章
相关标签/搜索
本站公众号
   欢迎关注本站公众号,获取更多信息