Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Random background imaged fixed problem!

    hello! i need your help!
    i use the random background script of this page:
    http://www.groan-zone.net/jscript/random.html

    it works perfectly, but the thing is that i want the background to be fixed...

    i have tried so many things but i cant do it and i need your help!!

    thank you!

    Code:
    <script language="JavaScript">
    <!-- Activate cloaking device
    var randnum = Math.random();
    var inum = 4;
    // Change this number to the number of images you are using.
    var rand1 = Math.round(randnum * (inum-1)) + 1;
    images = new Array
    images[1] = "zebra.jpg"
    images[2] = "tiler3.jpg"
    images[3] = "wicker3.jpg"
    images[4] = "aaa4.jpg"
    // Ensure you have an array item for every image you are using.
    var image = images[rand1]
    // Deactivate cloaking device -->
    </script>
    Code:
    <script language="JavaScript">
    <!-- Activate cloaking device
    document.write('<body background="' + image + '" text="white">')
    // Deactivate cloaking device -->
    </script>

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    1. Replace language="javascript" with type="text/javascript" the earlier is deprecated.
    2. background and text are deprecated attributes
    3. For your problem, I'm not certain if I get you, but have a try on changing this part:
      Code:
      document.write('<body background="' + image + '" text="white">')
      to:
      Code:
      document.write('<body style="color:#fff;background-image:url('+image+');background-position:fixed;">')
      Highlighted tells that your background is positioned fixed.


    Hope it helps.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    unfortunately this didn't help me....

    what i must do to fix it?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,922
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Please explain what you mean by "the background must be fixed".
    The background image covers the whole screen.

  • #5
    New Coder
    Join Date
    Jul 2008
    Location
    Peterborough - UK
    Posts
    63
    Thanks
    4
    Thanked 9 Times in 9 Posts
    as another poster has already said, using HTML attributes is the old (and depreciated) way of doing things - these days we try to use CSS where we can.

    However, you didn't write the script so rather than moan about using obsolete methods I'll try and fix your issue

    Try changing:

    Code:
    document.write('<body background="' + image + '" text="white">');
    to
    Code:
    document.write('<body background="' + image + '" text="white" behavior="fixed">');
    This still uses the old HTML attribute method of fixing the background (as in, fixed relative to the browser window - change 'fixed' to 'scroll' to have it act normally).

    Of course, the better way would be to fix the background using:
    Code:
    style="background-position: fixed;"
    in place of the
    Code:
    behavior="fixed"
    Try both out, and let me know how you fare!
    Last edited by Mikebert4; 07-30-2008 at 05:05 PM.

  • #6
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    i say that the random code works perfectly but i want scrolling the page, the background photo to be steady....the position to be fixed....how can i express that....everyone i believe understood what i mean...i believe...

  • #7
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Mikebert4 View Post
    as another poster has already said, using HTML attributes is the old (and depreciated) way of doing things - these days we try to use CSS where we can.

    However, you didn't write the script so rather than moan about using obsolete methods I'll try and fix your issue

    Try changing:

    Code:
    document.write('<body background="' + image + '" text="white">');
    to
    Code:
    document.write('<body background="' + image + '" text="white" behavior="fixed">');
    This still uses the old HTML attribute method of fixing the background (as in, fixed relative to the browser window - change 'fixed' to 'scroll' to have it act normally).

    Of course, the better way would be to fix the background using:
    Code:
    style="background-position: fixed;"
    in place of the
    Code:
    behavior="fixed"
    Try both out, and let me know how you fare!
    unfortunately no again....thanks for trying....

  • #8
    New Coder
    Join Date
    Jul 2008
    Location
    Peterborough - UK
    Posts
    63
    Thanks
    4
    Thanked 9 Times in 9 Posts
    Silly Mikebert - it's

    Code:
    background-attachment: fixed;
    so the final code looks like:

    Code:
    document.write('<body background="' + image + '" style="color: white; background-attachment: fixed;">');
    try that out for size

    (code was pulled from W3Schools - HERE)

  • Users who have thanked Mikebert4 for this post:

    vassileios_gr (07-30-2008)

  • #9
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    YES !!! YES!!! this worked!!!!!!!!

    Thank you man!!!!!!!!!!!

    great job!

  • #10
    New Coder
    Join Date
    Jul 2008
    Location
    Peterborough - UK
    Posts
    63
    Thanks
    4
    Thanked 9 Times in 9 Posts
    hehe, no problem! Happy coding!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •