Help~ Javascript fix background image doesnt work

Discussion in 'JavaScript' started by weilies, Apr 1, 2010.

  1. #1
    Greeting all,

    can anyone spot my error? i can hv my image display but the image is not fix while i scroll
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html class="sIFR-hasFlash"><head>
    
    
    
    </head><body id="product">
    
    dddddd<br> ... my content...
    dddddd<br>
    
    <script language="JavaScript">
    <!--
    
    newImage = "url(http://localhost/bg2.jpg)";
    document.getElementById('product').style.backgroundImage = newImage;
    
    document.getElementById('product').backgroundAttachment="fixed";	
    //-->
    </script>
    
    </body></html>
    HTML:
     
    weilies, Apr 1, 2010 IP
  2. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    what ever happened to #product{background:url('http://localhost/bg2.jpg') fixed;}?
     
    krsix, Apr 1, 2010 IP
  3. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #3
    erm. this works:
    document.body.style.backgroundImage = "url(http://forums.digitalpoint.com/image.php?u=126037&dateline=1201615683)";
    document.body.style.backgroundAttachment = "fixed";
    Code (javascript):
    you are missing .style. on your second line. working test: http://www.jsfiddle.net/bsXNU/1/
     
    dimitar christoff, Apr 1, 2010 IP
  4. weilies

    weilies Peon

    Messages:
    453
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks pal! it worked!
     
    weilies, Apr 4, 2010 IP