http://stackoverflow.com/questions/6065169/requestanimationframe-with-this-keyword
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的更多相关文章
- http://stackoverflow.com/questions/12601907/loading-google-maps-in-anonymous-function
http://stackoverflow.com/questions/12601907/loading-google-maps-in-anonymous-function window.gMaps ...
- 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 ...
- https://stackoverflow.com/questions/40949967/running-storm-from-intellij-nimbus-error
https://stackoverflow.com/questions/40949967/running-storm-from-intellij-nimbus-error 0down votefavo ...
- https://stackoverflow.com/questions/16130292/java-lang-outofmemoryerror-permgen-space-java-reflection
https://stackoverflow.com/questions/16130292/java-lang-outofmemoryerror-permgen-space-java-reflectio ...
- 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
- 国外的非常好的开发提问回答的网站https://stackoverflow.com/questions
https://stackoverflow.com/questions 可以进行搜索,在页面顶部,有搜索输入框
- 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 ...
- IIS Express 域认证问题(https://stackoverflow.com/questions/4762538/iis-express-windows-authentication)
option-1: edit \My Documents\IISExpress\config\applicationhost.config file and enable windowsAuthent ...
- 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 ...
随机推荐
- 3DTouch开发 (基础)
一.3DTouch开发准备工作(让模拟器也支持 3DTouch 的解决办法) 需要支持3DTouch的设备,如iPhone6s或以上.iOS9或以上.Xcode7或以上,估计很多和我一样的屌丝还没有i ...
- Linux内核设计第三周——构造一个简单的Linux系统
Linux内核设计第三周 ——构造一个简单的Linux系统 一.知识点总结 计算机三个法宝: 存储程序计算机 函数调用堆栈 中断 操作系统两把宝剑: 中断上下文的切换 进程上下文的切换 linux内核 ...
- oracle 用户锁定及到期
select * from dba_users where username='HR'--查询用户状态 alter user HR identified by HR;--重新更新密码alter use ...
- alibaba的FastJson(高性能JSON开发包),fastjson 使用demo
这是关于FastJson的一个使用Demo,在Java环境下验证的 class User{ private int id; private String name; public int getId( ...
- fiddler note
一晚上终于找到对的东西,作者很专业,这里作为笔记,想学习好东西还是到作者那里^_^ ---------------------------------------------------------- ...
- Salesforce select字段的多少对性能影响巨大
Salesforce select字段的多少对性能影响巨大,第1个是select 144个字段,第2个是select 5个字段, 性能相差了7倍 "select Id,IsDeleted,M ...
- 。。。contentType与pageEncoding的区别。。。
今天,开始换了一个新的开发工具IDEA,目前还不熟悉,新建了一个简单的Web项目,用到了Servlet,out.print("大家好!");然后就输出乱码了,用了response. ...
- Android -- 是时候来了解一波EventBus了
1,最早在项目中使用EventBus是在去年的时候,但自己一直没抽出时间来记录记录一下,今天就来简单的使用一下,先看一下EventBus的定义是什么 EventBus:是一个发布 / 订阅的事件总线. ...
- 重新安装了mysql,以前的数据库如何导入到新的数据库
重新安装了mysql,以前的数据库如何导入到新的数据库,导入到新的数据库不能用真么办? 将之前的mysql中的data目录中的数据库文件夹,(需要哪个数据库复制哪个,不要都复制) D:/wamp/bi ...
- jQuery Validate input是动态变化的
表单验证 $("#dataList").append("<div id='data"+dataNum+"' style='padding-top ...