PDA

View Full Version : Elastic Background Image??


ByteWizard
02-10-2003, 08:01 AM
Is there any way to make a fixed background image elastic?

OR

Can I capture the resolution of the client machine and modify the style sheet on the fly to reflect a different size background image for different resolutions?

animgirl
02-10-2003, 09:07 AM
Maybe you could just set the width & height to 100%

Maglor
02-10-2003, 02:13 PM
You can have an "Elastic Background Image" if you use JavaScript but there is no way to do it with html or css.

See here for a way to do it Elastic Background (http://www.webreference.com/dhtml/diner/bgresize/)

GDS
02-11-2003, 02:02 AM
The Screen object contains info on screen resolution:

screen.width
screen.height
screen.availHeight
screen.availWidth


The example Maglor mentioned, will make the the background
distort. I don't know what is most important, to keep the background undisturbed or show the whole background image or if it is okay to resize the window to an accurate
proportion of width and height.

Here is an example with javascript
made for InternetExplorer. It forces resizing of window
to adapt the height to the width selected by the user:

(NB DO NOT PREWIEW IN 1st Page!)

<html>
<head>
<title>Stretchy background</title>
<style>
body{ margin:0px;}
h1{color:red; text-align:center;}
.stretchy{
position:absolute;
width:100%;
z-index:-1;
}
</style>

<script>
var z;
function init(){
z=bg.offsetWidth/bg.offsetHeight;
adjust();
}

function adjust(){
var b=document.body
var width=b.offsetWidth;
var height=b.offsetHeight;
var newHeight=width/z;
self.resizeBy(0,newHeight-height)

}

// Do not prewiew in 1st Page, as it will hang!
// 1stPage dont like it's prewiew window
// to be resized by scripting.

</script>
</head>
<body scroll=no onresize="adjust()" onload="init()">
<img id="bg" class="stretchy" src="backgroundImage.jpg">
<br>
<br>
<h1>Heading</h1>
</body>
</html>


GDS

DCElliott
02-11-2003, 06:16 AM
I've seen code that keeps the proper aspect ratio of the image. I just can't remember where.

BTW - it doesn't necessarily have to be a background, does it, it could be a div with the "bottom" z-index floating over a compatible colored body background.

DE

ByteWizard
02-11-2003, 06:18 AM
Thanks for the leads. This gives me some things to work on...

Mike_Thomas
02-16-2003, 01:35 PM
Hi Everyone,

This is my first post in this forum. I use 1stPage and am looking forward to the new version. I am a graphics artist, designer, Paint Shop Pro tutorial author, programmer and regular columnist for the pspPower newsletter. Jasc software included 10 of my tutorial in the latest release of Paint Shop Pro.

It is not possible to "really" resize an image with JavaScript, or any form of scripting/coding. You can resize an image (background or foreground) using the image height and width attributes, but that will not increase or decrease the number of pixels used to draw the image. So the result of any form of height or width manipulation (even using the correct relative proportions) will result in a digression of the quality of the image.

mike
http://www.udraw2.com

ByteWizard
02-24-2003, 07:45 AM
Greetings Sunny Mike...

Glad to have your expertise around here. I worked around my "challenge" by making the image very large and positioning it so that larger resolutions would still get the image and the smaller ones would get the main focus of the image.

Again, welcome. Y'all come back now, ya hear.

Mike_Thomas
02-24-2003, 07:56 AM
That is the work around that I use.

mike

Zero Angel
02-25-2003, 12:58 AM
Not a big fan of javascript, so I made my own CSS to achieve the effect, take a look at this:<html>
<head>
<title>Test Page</title>
<style type="text/css">
<!--
body { margin: 0px; }
#bgimage {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
z-index: -100;
}
#mainbody { padding: 10px; }
-->
</style>
</head>
<body>

<img src="zalogofade.jpg" height="100%" width="100%" id="bgimage">
<div id="mainbody">

Content goes here!

</div>
</body>
</html>

Mike_Thomas
02-25-2003, 03:56 AM
A javascript solution does not change the number of pixels. so the end result is a distortion of the image. that being said, if you don't mind the distortion, then that's cool.

mike

Mike_Thomas
02-25-2003, 05:09 PM
I should have posted neither a javascript or css solution will increase or decrase the number of pixels.

mike