Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make background a watermark within javascript code to stretch image

Status
Not open for further replies.

brainpower

Technical User
Jul 20, 2003
3
US
HI,

I got the code to stretch the background picture to the size of the window at the website ( The code is pasted below.

THe only thing is when the page gets a scroll bar (when there is more than 1 page of text) and you scroll down there is only the white background after the picture that has stretched to window size.

The solution to this is if i can make the background a watermark at the same time have the background stretch with the window size. How can i achieve the watermarl effect witht he code below?

I tried using the bgproperties="fixed" and the style parameter background-attachment:fixed but it did not work. Any other suggestions?

---------------Code--------------

<head>

<SCRIPT LANGUAGE=&quot;JavaScript1.2&quot;>
<!--
NS4 = (document.layers);
IE4 = (document.all);

scaleWidth = true;
scaleHeight = true;
imSRC = &quot;skiff.jpg&quot;;

if (NS4) window.onload = setResize;

function setResize(){
setTimeout(&quot;window.onresize=reDo;&quot;,500);
}

function reDo(){
window.location.reload()
}

if (IE4) window.onresize = reDoIE;

function reDoIE(){
imBG.width = document.body.clientWidth;
imBG.height = document.body.clientHeight;
}

function makeIm() {

winWid = (NS4) ? innerWidth : document.body.clientWidth;
winHgt = (NS4) ? innerHeight : document.body.clientHeight;

imStr = &quot;<DIV ID=elBGim&quot;
+ &quot; STYLE='position:absolute;left:0;top:0;z-index:-1'>&quot;
+ &quot;<IMG NAME='imBG' BORDER=0 SRC=&quot; + imSRC;
if (scaleWidth) imStr += &quot; WIDTH=&quot; + winWid;
if (scaleHeight) imStr += &quot; HEIGHT=&quot; + winHgt;
imStr += &quot;></DIV>&quot;;

document.write(imStr);

}
//-->
</SCRIPT>

</head>

<BODY MARGINHEIGHT=0 MARGINWIDTH=0>
<SCRIPT LANGUAGE=&quot;JavaScript1.2&quot;>
<!--
makeIm();
//-->
</SCRIPT>
 
Your script doesn't actually set the document's background at all. It creates a div tag the same size as the content window of your screen and puts an img tag inside it. (Just be glad you didn't pay for &quot;code to stretch the background picture to the size of the window&quot;)

Probably the only way around your problem would be to now scroll the div tag with your page as per any of the hundred &quot;Watermark&quot; scripts available.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top