Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #13511

Re: Preloading PNGs & assigning as bkgd-image

From Stefan Weiss <krewecherl@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Preloading PNGs & assigning as bkgd-image
Date 2012-04-21 20:50 +0200
Organization albasani.net
Message-ID <jmuvi6$vul$1@news.albasani.net> (permalink)
References <f8s5p7dci7llr8kc70odlcq42fjilmbed4@4ax.com>

Show all headers | View raw


On 2012-04-21 20:20, Puzzled wrote:
> Supposedly, this should create an image object in the document's
> cache and load the bits into it:
> 
> var foo = new Image(70,25) ;  
> foo.src = 'mumble/fratz.png' ;
> foo.name = 'fratz' ;
> 
> but console.log('image count',document.images) returns the empty
> array and ~.length) returns 0, suggesting that I didn't get the
> syntax right after all.  Or that Image() isn't working, even
> though Firebug doesn't complain .

Or that your assumption that new Image objects automatically land in
document.images is incorrect. If there are no other errors, the data
from fratz.png will eventually be stored in the foo object and
(hopefully) the browser cache. But since the image is never added to the
document, document.images will still be empty.

To be notified when an image has finished loading, you can use foo.onload.

> To assign the image, if the preload were working, what syntax
> would I use?
> 
> document.getElementById('some_td_id').style.background-image =
> foo.src ;

... style.backgroundImage = ...


- stefan

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Preloading PNGs & assigning as bkgd-image Puzzled <scratching.head@example.com> - 2012-04-21 14:20 -0400
  Re: Preloading PNGs & assigning as bkgd-image Stefan Weiss <krewecherl@gmail.com> - 2012-04-21 20:50 +0200
    Re: Preloading PNGs & assigning as bkgd-image Puzzled <scratching.head@example.com> - 2012-04-22 06:12 -0400
      Re: Preloading PNGs & assigning as bkgd-image Stefan Weiss <krewecherl@gmail.com> - 2012-04-22 20:18 +0200
  Re: Preloading PNGs & assigning as bkgd-image "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-04-21 18:56 +0000
    Re: Preloading PNGs & assigning as bkgd-image Puzzled <scratching.head@example.com> - 2012-04-22 07:07 -0400
      Re: Preloading PNGs & assigning as bkgd-image "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-04-23 10:22 +0000
        Re: Preloading PNGs & assigning as bkgd-image Stefan Weiss <krewecherl@gmail.com> - 2012-04-23 20:46 +0200
        Re: Preloading PNGs & assigning as bkgd-image Puzzled <scratching.head@example.com> - 2012-04-24 08:42 -0400
  Re: Preloading PNGs & assigning as bkgd-image SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-04-22 00:24 +0200

csiph-web