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. LeetCode Count of Range Sum

    原题链接在这里:https://leetcode.com/problems/count-of-range-sum/ 题目: Given an integer array nums, return th ...

  2. HTML5实现下载文件且指定下载文件名

    <a href="/files/adlafjlxjewfasd89asd8f.pdf" download="预算表.pdf">下载</a> ...

  3. 快速激活JetBrains PhpStorm WebStorm系列产品

    从官方网站下载正版PhpStorm 安装后,注册时选择“License server” 输入“http://idea.lanyus.com/” (不带双引号,后面的斜杠要带上) 完成 恭喜你 激活Je ...

  4. 帝国CMS内容模板IF判断

    [e:loop={'selfinfo',50,0,0,"jingshu=$navinfor[jingshu]","id"}]<?php$class1=&q ...

  5. 【转】SQLServerDBA十大必备工具---让生活轻松点

    曾经和一些DBA和数据库开发人员交流时,问他们都用过一些什么样的DB方面的工具,大部分人除了SSMS和Profile之外,基本就没有使用过其他工具了: 诚然,SSMS和Profile足够强大,工作的大 ...

  6. phpstorm-----------如何激活phpstorm2016

    新版激活方法: 1.在线激活 菜单help >>>> Register 选择License Server 输入 http://idea.qinxi1992.cn/ 点击ok 2 ...

  7. Linux命令之tcpdump

    项目中常用到的抓包命令: 1. tcpdump -i eth0:1 udp poort 6015 -Xvv 2. tcpdump host 239.16.101.27 -Xvv 3. tcpdump ...

  8. PL301 matrix内部模块

    ASIB中的valid信号,有两部分,一部分add产生的地址映射,到main中的default addr.(vect) 一部分由Dmu和Cdas组成,到main中的build. Dmu:interco ...

  9. Qt之界面实现技巧

    一.主界面 1.窗口 最小化 最小化 关闭按钮 显示状态自定义 setWindowFlags(Qt::CustomireWindowHint); setWindowFlags(Qt::WindowCl ...

  10. 白话LINQ系列2---以代码演进方式学习LINQ必备条件

    今天,我们通过一个简单的示例代码的演进过程,来学习LINQ必备条件:隐式类型局部变量:对象集合初始化器:委托:匿名函数:lambda表达式:扩展方法:匿名类型.废话不多说,我们直接进入主题. 一.实现 ...