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 ...
随机推荐
- 几个常见Win32 API函数
1.获取客户区矩形区域 RECT cliRect; GetClientRect(hWnd, &cliRect); 2.获取窗口上下文句柄 HDC hdc = GetDC(hWnd);//... ...
- 关于队列queue
1.在多线程和多进程中都有queue.调用方式不同,使用方式一致: 线程中: import queue q = queue.Queue(maxsize = 2) 进程中: from multiproc ...
- MySQL导入.sql文件及常用命令
在MySQL Qurey Brower中直接导入*.sql脚本,是不能一次执行多条sql命令的,在mysql中执行sql文件的命令: mysql> source d:/myprogram/d ...
- 字节流与字符流(FileInputStream类和FileOutputStream类)
FileInputStream类和FileOutputStream类中,第一个类的源端和第二个类的目的端都是磁盘文件,它们的构造方法允许通过文件的路径名来构造相应的流.例如: FileInputSte ...
- RDIFramework.NET开发实例━表约束条件权限的使用-Web
RDIFramework.NET开发实例━表约束条件权限的使用-Web 在上一篇文章“RDIFramework.NET开发实例━表约束条件权限的使用-WinForm”我们讲解了在WinForm下表约束 ...
- Leetcode: Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...
- Leetcode: Minimum Number of Arrows to Burst Balloons
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...
- 通过setDB2Client*来方便的使用TRACE调优jdbc程序
一般来说通过TRACE的report来分析DDF的性能问题的话,基本对DBA都是噩梦一样.因为所有的Thread都是通过DDF一个类型的Thread,所以不管你怎么分类,看Accounting rep ...
- YTU 2345: 后序遍历二叉树
原文链接:https://www.dreamwings.cn/ytu2345/2611.html 2345: 后序遍历二叉树 时间限制: 1 Sec 内存限制: 128 MB 提交: 3 解决: ...