1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development Javascript in CSS

Discussion in 'Software' started by 3N1GM4, 2 Mar 2004.

  1. 3N1GM4

    3N1GM4 What's a Dremel?

    Joined:
    23 Jun 2003
    Posts:
    685
    Likes Received:
    0
    im trying to get a javascript random image genorator that i made to work with css backgrounds... is this at all possible or is this just a futile attempt?

    thanks
     
  2. NiHiLiST

    NiHiLiST New-born car whore

    Joined:
    18 Aug 2001
    Posts:
    3,987
    Likes Received:
    6
    It should work fine if you're using inline styles, but the JS won't be executed if you're trying to use it in an external style sheet.
     
  3. 3N1GM4

    3N1GM4 What's a Dremel?

    Joined:
    23 Jun 2003
    Posts:
    685
    Likes Received:
    0
    it seems to work with an external like, if i have it document.write("klajdf"); it outputs that, but it never seems to get the image name from the javascript :grr:
     
  4. 3N1GM4

    3N1GM4 What's a Dremel?

    Joined:
    23 Jun 2003
    Posts:
    685
    Likes Received:
    0
    w00t i got it working... i decided to just have the javascript write the line for the div... like so

    Code:
        function randbackground()
    	 {
    	  	return document.write("<div id=container style='background-image: url( " + bgimage[randimg] + ")'>");
    	 } 
    works like a charm... not sure how "correct" it is but untill some one else shows me the "correct" way to do it, im gunna use this
     
  5. Hepath

    Hepath Minimodder

    Joined:
    20 Oct 2003
    Posts:
    730
    Likes Received:
    0
    Pretty good: :thumb:

    OK this is from memory:
    Have you tried it for cross-browser support? The function will probably be supported by most newer browsers , but writing to the document on the fly can be tricky in Nutscrape versions prior to v6, These used/required <LAYER> tags - which IE didn't support requiring not only browser detection but its version as well (I'm not even thinking about MACs here :naughty: )

    Stu
     

Share This Page