Changing image causes big lag

我的未来我决定 提交于 2019-12-12 02:03:54

问题


I have a problem that after clicking on thumbnail(mini picture that causes change background on canvas),page will start lag and if you more and more click to other thumbnails, lags are very big and other effect is that text does not appear after change image(this is connected with these lags I think again) Could someone tell me where is problem or just look at my code and try to repair it?

thanks so my because I really do not know where is problem:(

http://codepen.io/anon/pen/ydxIH


回答1:


http://codepen.io/anon/pen/bsdHp

the main error here was that you were doing:

    layer.add(yoda);
    layer.add(vrchnyText);
    layer.add(spodnyText);
    stage.add(layer); 

on every click of a picture.

This slowed down everything because you were not 'changing' the picture and text, you were 'adding' it each time. So what you want to do is to change the the picture and text, not add it each time, then just draw the layer again.

    vrchnyText.setText($(this).val().toUpperCase());
    layer.draw();

Also, you do not need to change the width and height of the stage and picture each time, since it is always 500, this REALLY slows it down.



来源:https://stackoverflow.com/questions/14725432/changing-image-causes-big-lag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!