Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent large image flickering on src change

I've a problem with image flickering with large images. In my body i have 5 images:

<img id="img1" src="img1.png" width="250">
<img id="img2" src="img2.png" width="250">
<img id="img3" src="img3.png" width="250">
<img id="img4" src="img4.png" width="250">
<img id="img5" src="img5.png" width="250">

and one I'm dragging one of them with jQuery UI, all are changing their src and on dragend as well:

function dragStart() {
        $('#img2').attr('src','newimg2.png');
        $('#img3').attr('src','newimg3.png');
        $('#img4').attr('src','newimg4.png');
        $('#img5').attr('src','newimg5.png'); }

so fine so good. But I need to use large images (2000 x 2000px) because all images can be clicked and then they will animate to the full size of the viewport that they dont pixelate.

$this.animate(
                { width: 1800, top: -650, left: -250 }, 

                {
                    duration: 4000,
                    easing: 'easeOutElastic'
                }) 

I think because of the size of every image, they are flickering. Does anyone of you have an idea how to prevent this flickering on images, if all src change at the same time ?

Thanks for your effort

like image 603
supersize Avatar asked May 24 '13 14:05

supersize


1 Answers

The problem you described does not sound like a pre-loading issue to me.

For preloading would happen, when you load ANOTHER image from the server once you start to move it around. But like I have read your Question you are moving the DOM-object containing your image in SRC around.

Thats most likely a Browser issue, because he has to scale your images down from 2k x 2k to lets say 100 x 100. That is some expensive interpolation stuff to do there. So your main problem could be, like you mentioned, the size of the image.

Even preloading would not be of use, because you would have the same issues then.

In my eyes you should have two versions of your image: One small one (the size you want to drag around) and a big one, the one you want to display. The big one can either be loaded automatically in background or on demand, when a user clicks on an image. In the web it is quite common, to show scale the small image to screen size with smooth animations and start to preload in the background and when the preload finished, replace the fullscreen image to remove the pixel effect.

I hope I made myself clear.

like image 82
EGOrecords Avatar answered Sep 28 '22 11:09

EGOrecords