0

I have a javascript code to control the animation a moving div.In this I used setTimeout to make the div move. you can click on the following link to play the animation.

     `http://jsfiddle.net/dudling007/PfPzj/3/`

The problem is that after playing the animation, whenever I clicked a couple of time on pause and resume buttons , it takes a lot of memory and the clicking of the pause buttons also become so slow. I saw the %CPU and real memory consumption from the activity monitor of the MAC OSX.Can someone please help me what is the problem in the code that is consuming some much memory after clicking the pause button 10 -14 times.

4

1 回答 1

1

发生内存泄漏是因为$('#pause_button').click每次moveCard调用方法时都会设置事件。按钮绑定应该移出“对象”循环。

您可以使用firefox的工具链接firebug来检查 javascript 的控制台日志。这是带有登录暂停按钮的示例。这应该只发生一次。http://jsfiddle.net/Th6ha/1/

$('#pause_button').click(function() { 
console.log('pause pressed');
                      arrayObject.pause(wStart,lStart,wEnd,lEnd);
                      $('#resume_button').css('display','inline-block');
                      $('#pause_button').css('display','none');

                      }); 

您可以考虑使用jquery 的方法animate

于 2013-05-28T10:50:15.733 回答