Observe that you call obj.draw as :

<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.

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

Something like :

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.

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

http://stackoverflow.com/questions/6065169/requestanimationframe-with-this-keyword的更多相关文章

  1. http://stackoverflow.com/questions/12601907/loading-google-maps-in-anonymous-function

    http://stackoverflow.com/questions/12601907/loading-google-maps-in-anonymous-function   window.gMaps ...

  2. https://stackoverflow.com/questions/51751426/failed-to-run-the-da-platform-trial-vm

    https://stackoverflow.com/questions/51751426/failed-to-run-the-da-platform-trial-vm {  "annotat ...

  3. https://stackoverflow.com/questions/40949967/running-storm-from-intellij-nimbus-error

    https://stackoverflow.com/questions/40949967/running-storm-from-intellij-nimbus-error 0down votefavo ...

  4. https://stackoverflow.com/questions/16130292/java-lang-outofmemoryerror-permgen-space-java-reflection

    https://stackoverflow.com/questions/16130292/java-lang-outofmemoryerror-permgen-space-java-reflectio ...

  5. Service vs provider vs factory 转自:http://stackoverflow.com/questions/15666048/service-vs-provider-vs-factory

    请看此链接:http://stackoverflow.com/questions/15666048/service-vs-provider-vs-factory

  6. 国外的非常好的开发提问回答的网站https://stackoverflow.com/questions

    https://stackoverflow.com/questions 可以进行搜索,在页面顶部,有搜索输入框

  7. https://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth

    https://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth p.p ...

  8. IIS Express 域认证问题(https://stackoverflow.com/questions/4762538/iis-express-windows-authentication)

    option-1: edit \My Documents\IISExpress\config\applicationhost.config file and enable windowsAuthent ...

  9. https://stackoverflow.com/questions/10423781/sql-data-range-min-max-category

    select phone,count(order_id) as c from table_recordgroup by phoneorder by c desc SELECT CASEWHEN (ag ...

随机推荐

  1. rabbimq之流控

    rabbitmq为了能够保证服务器在大量使用资源的情况下正常工作,会做流控. 所谓流控有以下两个方面.一是针对连接做流控,即降低某频率过快的发送消息.二是整体流控,即将所有消费者发送的消息丢掉,悄无声 ...

  2. UIWebView如何获取内容高度

    iOS UIWebView如何获取到内容的高度呢?我们经常会遇到项目中需要使用UIWebView来加载H5页面,但是页面的高度并不确定,而我们前端需要根据内容的高度呈现出来,且不允许webview滚动 ...

  3. Construct Binary Tree from Inorder and Postorder Traversal || LeetCode

    /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * s ...

  4. MySQL 的 utf8_general_ci 和 utf8_unicode_ci 有什么区别,应如何选择?

    一般的解说是 utf8_general_ci 速度较快,utf8_unicode_ci 准确性较好 … 但快在那里,又好在什么地方呢? 首先就其准确性说,这世界上有无数种文字,除了通用的英文使用我们较 ...

  5. js 中escape,encodeURI,encodeURIComponent的区别

    escape:方法不能能够用来对统一资源(URI)进行编码,对其编码应使用encodeURI和encodeURIComponent encodeURI:encodeURI ()方法返回一个编码的 UR ...

  6. 决策树Decision Tree 及实现

    Decision Tree 及实现 标签: 决策树熵信息增益分类有监督 2014-03-17 12:12 15010人阅读 评论(41) 收藏 举报  分类: Data Mining(25)  Pyt ...

  7. Matlab的XTickLabel中数值带下标

    %axis为'x'或'y',分别表示更改x或y刻度 %ticks是字符cell function settick(axis,ticks) n=length(ticks); tkx=get(gca,'X ...

  8. ActiveMQ的使用笔记(基本实现原理)

    具体原理不进行深入,会用就好. 第一:当然是先安装ActiveMQ,选择操作系统位数,安装成功以后,输入网址http://ip:8161/admin/,会出现相关页面,账号密码都是admin.在这个页 ...

  9. transform原点

    Safari 4 Firefox3.5 Opera10.5 Chrome Internet Explorer 目前这两个属性得到了除去ie以外各个主流浏览器webkit,firefox,opera的支 ...

  10. MyEclipse项目中的包按层次显示

    MyEclipse项目中的包按层次显示 如下图所示: window >  Navigation > Show View Menu  >  Package Presentation   ...