问题
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