Can someone help me with this statement...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Vasquez

    #1

    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","sk ysong2","mornin glight","anen", "thetismoon ","v
    alley2k","fluor escence","indra ","neuron","blu edome","beeds"]

    fnChangeBg = function (nIndex) {
    var _bg = new Image()
    defaultStatus = "Loading background image ["+arBgs[nIndex]+"]. Please
    wait..."
    _bg.onload = function () {
    _cover.style.ba ckgroundImage = "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.ran dom() * (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

    #2
    Re: Can someone help me with this statement...

    In article <jdz_a.11483$M6 .980997@newsrea d1.prod.itd.ear thlink.net>,
    condorschool@ea rthlink.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.ba ckgroundImage = "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!


    -------------------------------------------------

    Comment

    • Tony Vasquez

      #3
      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]


      Comment

      • kaeli

        #4
        Re: Can someone help me with this statement...

        In article <NiW_a.1597$f15 .153995@newsrea d1.prod.itd.ear thlink.net>,
        condorschool@ea rthlink.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!


        -------------------------------------------------

        Comment

        Working...