Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

preload an animated gif

I have a feature where a user can click a video thumbnail and my PHP script will go grab the video.

I have a div which is display: none; containing the flash video player code and its background image is the animated gif (a loading spinner) in the CSS. I use the jQuery show method to make it appear when the user clicks it.

But when the div is clicked the loading image needs to be fetched as well. Since the video is also being fetched at the same time, the loading image rarely shows up at all.

How can I preload this image without making it part of another image using the negative margin trick???

like image 815
stunnaman Avatar asked Dec 30 '22 01:12

stunnaman


1 Answers

Put this javascript somewhere in the page so that it executes on load:

var image = new Image();
image.src = 'path/to/spinner.gif';
like image 182
Paolo Bergantino Avatar answered Jan 08 '23 01:01

Paolo Bergantino