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!

stretching an img bg to fit screen

Status
Not open for further replies.

hablablow

Programmer
Sep 9, 2000
115
FR
Hello,

I would like a background image to fit the navigator window.
I could use a 100 % width and height in a 100 % W&H table, but
it is buggy on all navigators except IE.
So i am using this script below.
---------------------------------------------

First i detect wich navigator is in use

----------------------------------------------

agent = navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
this.ns = ((agent.indexOf('mozilla') != -1) && ((agent.indexOf('spoofer')
== -1)
&& (agent.indexOf('compatible') == -1)));
this.ns2 = (this.ns && (this.major == 3));
this.ns3 = (this.ns && (this.major == 3));
this.ns4b = (this.ns && (this.major == 4) && (this.minor <= 4.03));
this.ns4 = (this.ns && (this.major == 4));
this.ns6 = (this.ns && (this.major >= 5));
this.ie = (agent.indexOf(&quot;msie&quot;) != -1);
this.ie3 = (this.ie && (this.major < 4));
this.ie4 = (this.ie && (this.major == 4) && (agent.indexOf(&quot;msie 5.0&quot;)
== -1));
this.ie5 = (this.ie && (this.major == 4) && (agent.indexOf(&quot;msie 5.0&quot;)
!= -1));
this.ie55 = (this.ie && (this.major == 4) && (agent.indexOf(&quot;msie 5.5&quot;)
!= -1));
this.ie6 = (this.ie && (agent.indexOf(&quot;msie 6.0&quot;)!=-1) );
this.aol = (agent.indexOf(&quot;aol&quot;) != -1);
this.aol3 = (this.aol && this.ie3);
this.aol4 = (this.aol && this.ie4);
this.aol5 = (this.aol && this.ie5);
}
var is = new Is();

function winResize() {
if(is.ns4 ||is.ns6||is.ie4||is.ie5||is.ie55||is.ie6) {
history.go(0);
}
}
---------------------------------------------

Then it stretches a div containing the image on all the available screen width.

----------------------------------------------

<div id=&quot;backgroundLayer&quot; style=&quot;position:absolute; width:694px;
height:331px; z-index:1; left: 0px; top: 0; visibility: visible&quot;>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>

if(is.ns4 || is.ns6) {
available_width = innerWidth;
available_height = innerHeight;
}

else if(is.ie4 || is.ie5 || is.ie55 || is.ie6) {
available_width=document.body.clientWidth;
available_height=document.body.clientHeight;
}

if(is.ie4 || is.ie5 || is.ie55 || is.ie6 || is.ns6 || is.ns4) {
image1_width = (available_width * 1.00);
image1_height = (image1_height * (available_width / image1_width));
var image1 = '<img src=&quot;1.jpg&quot; width=&quot;' + image1_width
+ '&quot; height=&quot;' + image1_height + '&quot;>';

document.write(image1);
}
</script>
</div>

-----------------------------------------------------

Of course we have to maintain the img proportions
when stretched: that is why i am using a ratio to calculate
the img height : image1_height = (image1_height * (available_width / image1_width))

Now this is hopefully working in
NETSCAPE 7
MOZILLA
PHOENIX

But it won't in
MSIE
OPERA

very buggy in
NETSCAPE 4

Can somebody out there help me to debug this ?

thanks for your incomming messages.
Hab.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top