vassileios_gr
07-29-2008, 11:46 PM
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!
<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>
<script language="JavaScript">
<!-- Activate cloaking device
document.write('<body background="' + image + '" text="white">')
// Deactivate cloaking device -->
</script>
rangana
07-30-2008, 04:06 AM
Replace language="javascript" with type="text/javascript" the earlier is deprecated.
background and text are deprecated attributes (http://www.codehelp.co.uk/html/deprecated.html)
For your problem, I'm not certain if I get you, but have a try on changing this part:
document.write('<body background="' + image + '" text="white">')
to:
document.write('<body style="color:#fff;background-image:url('+image+');background-position:fixed;">')
Highlighted tells that your background is positioned fixed.
Hope it helps.
vassileios_gr
07-30-2008, 04:35 PM
unfortunately this didn't help me....
what i must do to fix it?
Philip M
07-30-2008, 04:58 PM
Please explain what you mean by "the background must be fixed".
The background image covers the whole screen.
Mikebert4
07-30-2008, 05:01 PM
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 :p
Try changing:
document.write('<body background="' + image + '" text="white">');
to
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:
style="background-position: fixed;"
in place of the
behavior="fixed"
Try both out, and let me know how you fare!
vassileios_gr
07-30-2008, 05:04 PM
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...
vassileios_gr
07-30-2008, 05:07 PM
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 :p
Try changing:
document.write('<body background="' + image + '" text="white">');
to
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:
style="background-position: fixed;"
in place of the
behavior="fixed"
Try both out, and let me know how you fare!
unfortunately no again....thanks for trying....
Mikebert4
07-30-2008, 05:22 PM
Silly Mikebert - it's
background-attachment: fixed;
so the final code looks like:
document.write('<body background="' + image + '" style="color: white; background-attachment: fixed;">');
try that out for size ;)
(code was pulled from W3Schools - HERE (http://www.w3schools.com/css/tryit.asp?filename=trycss_background-attachment))
vassileios_gr
07-30-2008, 05:27 PM
YES !!! YES!!! this worked!!!!!!!!
Thank you man!!!!!!!!!!!
great job!
Mikebert4
07-30-2008, 05:33 PM
hehe, no problem! Happy coding! ;)