473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Can someone help me with this statement...

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
Jul 20 '05 #1
3 1350
In article <jd*******************@newsread1.prod.itd.earthlin k.net>,
co**********@earthlink.net enlightened us with...
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?!


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
-------------------------------------------------
Jul 20 '05 #2
Thanks so much! I now get what I was missing. Thanks so much for answering
my question so thoroughly. :) Much obliged.

Tony

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
-------------------------------------------------

Jul 20 '05 #3
In article <Ni*******************@newsread1.prod.itd.earthlin k.net>,
co**********@earthlink.net enlightened us with...
Thanks so much! I now get what I was missing. Thanks so much for answering
my question so thoroughly. :) Much obliged.

Tony


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
-------------------------------------------------
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike Chirico | last post by:
Hopefully this will help someone... Helpful Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Last Updated: Fri Apr 16 11:47:34 EDT 2004 The latest version of this...
3
by: Amy | last post by:
Hi, I have 6 If Then Else statements I was supposed to write. I did so but I know that they have to be wrong because they all look the same. Could someone take a look at them and point me in the...
6
by: sparks | last post by:
extracalc = Switch(Me.Parent.Race_Black = -1 And Me.Parent.Sex = "Female", 1.952, Me.Parent.Race_Black = -1, 1.21, Me.Parent.Sex = "Female", 0.742, 1) I look at this and say ok if race = black...
6
by: amerar | last post by:
Hi All, I'm not good at Javascript, so I am trying to understand this small bit of code: var groups=document.$fm.category.options.length; var group=new Array(groups); for (i=0; i<groups;...
23
by: Tiny Tim | last post by:
I am new C program student. I wonder can we write a program in C that just trigger its function to do a certain action ? In this case, I have a program but it is not working. What I want is for...
2
by: blueyonder | last post by:
The statament below does exactly what I want it to do but I don't understand why? In my mind the subquery produces a result set which is a subset of the handset table which the initial part of...
8
by: Bart | last post by:
Could someone explain me what is wrong with this code ? I gives me a compile error: Error 1 Use of unassigned local variable 'fileStreamObject' C:\Documents and Settings\Bart\Local...
1
by: td0g03 | last post by:
Hello, I am new to C and I am new to English. I not sure what palindromes mean. I don't know exactly what my teacher wants me to do. If someone could explain it to me in a different way that would be...
1
by: okonita | last post by:
I need major help resolving a UDF error. My environment id DB2 UDBv8.2 and v9.1 on a Linux and Windows server. I am getting a SQL20148N error which states as follows: SQL20148N Routine...
6
by: Dave Young | last post by:
I'm looking at some code that i've inherited and I'm not really familar with what's going on here and was hoping somone could explain it to me. For reference: f1 is a long f2 is a long ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.