Re: Image preloading

ChaosKnight
2010-04-11T11:15:00Z

On Apr 11, 3:43 am, steve ross
<cwdi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> On Apr 10, 2010, at 9:32 AM, ChaosKnight wrote:
>
>
>
>
>
>
>
> > Hi, I am still very new to Ruby on Rails, but I''m busy with
my first
> > RoR website, everything went well, until I realized that my images
> > didn''t preload... On previous websites I used a simple
JavaScript
> > preloader that seemed to work very well:
>
> >    function preloadImages() {
> >      if (document.images) {
> >        var imgFiles = preloadImages.arguments;
> >        var preloadArray = new Array();
> >        for (var i=0; i < imgFiles.length; i++) {
> >          preloadArray[i] = new Image;
> >          preloadArray[i].src = imgFiles[i];
> >       }
> >     }
> >   }
>
> > And I called it from within the HTML:
>
> >    <body
onload="preloadImages(''/images/home.png'',....etc....)
>
> > This is how I called the image rollover in the Rails code:
> >    <%= link_to(image_tag(''home.png'',
:mouseover=>"home_ro.png"), ''/'',
> > {:controller=>''home'',
:action=>''index''}) %>
>
> > Can anyone please tell me why this didn''t work? I also heard
that
> > Prototype has it''s own built-in image preloader, is this
true?
>
> > Thanks I really appreciate your help!
>
> You''ll want to take the onload out of the body tag and do
something like this in your application.js file:
>
> document.observe("dom:loaded", function()
> {
>   preloadImages(''/images/home.png'',....etc....);}
>
> );

That still doesn''t work in Firefox... What about caching?
Won''t that
help?
Or perhaps and alternative solution that works better?

--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.