更改图像会导致较大的延迟 [英] Changing image causes big lag
问题描述
我有一个问题,即单击缩略图(会在画布上更改背景的小图片)后,页面将开始滞后,如果您越来越多地单击其他缩略图,则滞后会很大,而其他影响是文本不会更改图像后出现(这与这些滞后有关,我再三考虑)有人可以告诉我问题出在哪里还是只是看一下我的代码并尝试对其进行修复?
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
推荐答案
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);
每次点击图片
这会减慢所有速度,因为您没有更改"图片和文本,而是每次都添加"了图片和文字.因此,您要做的是更改图片和文字,而不是每次都添加,然后再次绘制图层.
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();
此外,您不必每次都更改舞台和图片的宽度和高度,因为它始终为500,因此确实会减慢其速度.
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.
这篇关于更改图像会导致较大的延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!