![]() |
Refreshing an image + preloading it
Hi guys,
Basically, I have a site which just basically uses the glob and array_rand functions to sweep my image dir and show a random image. Now, I would like to implement two things, however the main thing is to refresh the image, without refreshing the whole page. All it needs to be is a simple refresh: it doesn't need to know what image its going to show next, as the array_rand will sort that out on the refresh. This leads me onto something which I reckon is more complicated. The very fact that it doesn't know what it is showing next means that it can't preload it- another feature I wish to implement. I am not asking for any code (although I would really appreciate it if you did give me some), just your ideas on how they can be implemented.. Does anyone have any ideas? Gareth |
Use jQuery.
Make the image src point to your script, and append a querystring to the end with a unique number (using Date() / getSeconds()) every time you want to refresh the image (assuming you'll use something such as setInterval()) Using jQuery, you could use the load event to monitor when it's loaded, you might need to trigger this event each time you have refreshed the src - $('img').load(function(){ alert('loaded'); }); |
And how exactly would I refresh the image? Your last two paragraphs lost me, too :P
|
So you are looking for some code ;)
I've not tested this as I'm off to work now, you may have some problems in PC IE, if you do, let me know and I'll fix it for you. Code:
var refresh = setInterval(function(){ |
I'm really not following this, hehe. So am I correct in saying that I put the script as the source of the image with the time details? but how does the script know where to get the images etc? This is my php:
PHP Code:
|
| All times are GMT. The time now is 05:52 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0