jQuery Rollovers Not Preloading
Posted
by zuk1
on Stack Overflow
See other posts from Stack Overflow
or by zuk1
Published on 2009-07-09T11:39:19Z
Indexed on
2010/05/19
8:30 UTC
Read the original article
Hit count: 339
$('.ro').hover(
function(){
t = $(this);
t.attr('src',t.attr('src').replace(/([^.]*)\.(.*)/, "$1_o.$2"));
},
function(){
t = $(this);
t.attr('src',t.attr('src').replace('_o',''));
}
);
I use this code so that (for examle) test.gif with the class 'ro' would change to test_o.gif on rollover, the problem is when the images aren't in the cache there is lag on rollover and rolloff.
Basically if I clear my cache and visit the test page, everytime I rollover and rolloff the image it is loading the file each time, so you could sit there for hours and it would still be loading the rollover images each time. However, when I refresh the page and the images are now in the cache it works instantly, which is what I need to achieve.
I've tried using this
http://flesler.blogspot.com/2008/01/jquerypreload.html
plugin to preload the images with this
$.preload('.ro');
code, but it seems to have no effect.
Any ideas?
© Stack Overflow or respective owner