Connecting Tech Pros Worldwide Forums | Help | Site Map

Can someone help me with this statement...

Tony Vasquez
Guest
 
Posts: n/a
#1: Jul 20 '05
I am trying to modify my own web site to have a certain type of dynamic
background through divs... and such.... but what I need, is help with
this one script I have. I want to modify it to work on my site, but I can't
seem to figure out how this function works.

var arBgs =
["singularity","spellcraft","skysong2","morningligh t","anen","thetismoon","v
alley2k","fluorescence","indra","neuron","bluedome ","beeds"]

fnChangeBg = function (nIndex) {
var _bg = new Image()
defaultStatus = "Loading background image ["+arBgs[nIndex]+"]. Please
wait..."
_bg.onload = function () {
_cover.style.backgroundImage = "url("+this.src+")"; // THIS IS WHERE I
NEED HELP! WHAT DOES THIS LINE DO?!
defaultStatus = ""
}
_bg.src = "images/working_items/"+arBgs[nIndex]+".jpg"
fnChangeBg.i = nIndex
}
fnChangeBg(Math.floor(Math.random() * (arBgs.length)))

I guess what I am trying to ask is... what the hell does the _bg.onload
function do?! How does it work... I know most of it, but that one line,
throws me off, due to the THIS keyword. What HTML element does the THIS
word effect?! Anywho, please any help would be appreshiated.

Qzmicro



kaeli
Guest
 
Posts: n/a
#2: Jul 20 '05

re: Can someone help me with this statement...


In article <jdz_a.11483$M6.980997@newsread1.prod.itd.earthlin k.net>,
condorschool@earthlink.net enlightened us with...
[color=blue]
> fnChangeBg = function (nIndex) {
> var _bg = new Image()
> defaultStatus = "Loading background image ["+arBgs[nIndex]+"]. Please
> wait..."
> _bg.onload = function () {
> _cover.style.backgroundImage = "url("+this.src+")"; // THIS IS WHERE I
> NEED HELP! WHAT DOES THIS LINE DO?![/color]

It changes the source of the background image of the object _cover to
the image (source) pointed to by the variable _bg. That would be the
line
_bg.src = "images/working_items/"+arBgs[nIndex]+".jpg"

So the object pointed to by _cover would have a background of one of the
images in that string array at the beginning of the code.

The "this" keyword refers to the object (_bg). We know this because the
function is called on the object referred to by _bg. It runs when _bg
loads.

HTH

-------------------------------------------------
~kaeli~
Why do people who know the least know it the loudest?
If that cell phone was up your a$$, maybe you could
drive a little better!
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Tony Vasquez
Guest
 
Posts: n/a
#3: Jul 20 '05

re: Can someone help me with this statement...


Thanks so much! I now get what I was missing. Thanks so much for answering
my question so thoroughly. :) Much obliged.

Tony

[color=blue]
> It changes the source of the background image of the object _cover to
> the image (source) pointed to by the variable _bg. That would be the
> line
> _bg.src = "images/working_items/"+arBgs[nIndex]+".jpg"
>
> So the object pointed to by _cover would have a background of one of the
> images in that string array at the beginning of the code.
>
> The "this" keyword refers to the object (_bg). We know this because the
> function is called on the object referred to by _bg. It runs when _bg
> loads.
>
> HTH
>
> -------------------------------------------------
> ~kaeli~
> Why do people who know the least know it the loudest?
> If that cell phone was up your a$$, maybe you could
> drive a little better!
> http://www.ipwebdesign.net/wildAtHeart
> http://www.ipwebdesign.net/kaelisSpace
> -------------------------------------------------
>[/color]


kaeli
Guest
 
Posts: n/a
#4: Jul 20 '05

re: Can someone help me with this statement...


In article <NiW_a.1597$f15.153995@newsread1.prod.itd.earthlin k.net>,
condorschool@earthlink.net enlightened us with...[color=blue]
> Thanks so much! I now get what I was missing. Thanks so much for answering
> my question so thoroughly. :) Much obliged.
>
> Tony
>[/color]

You're welcome. :)

-------------------------------------------------
~kaeli~
Why do people who know the least know it the loudest?
If that cell phone was up your a$$, maybe you could
drive a little better!
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Closed Thread