472,958 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Switching the background-image according to resolution

Hi, everyone,
I have a special problem:

For every monitor resolution in 200 pixel steps from 800 to 1600
pixels I have an image to be shown as centered background-image.
Those images all have the same name and reside in the following
physical path structure:

/images/700/many_files_in_this_dir.png
/images/900/many_files_in_this_dir.png
/images/1100/many_files_in_this_dir.png
/images/1300/many_files_in_this_dir.png
/images/1500/many_files_in_this_dir.png

The basic idea is to selectively display the appropriate *.png file
for every *.html file to be opened on the website according to the
user's individual monitor resolution.

Now, I could do this job easily in PHP oder Perl, but the customer
wants to have it in JavaScript.

Some code snippet I have already tried to set up and show the basic
idea:

var file_to_be_displayed = something???;

if ((screen.width == 800) || (screen.width > 800) && (screen.width <=
1600) || (screen.width > 1600)) {
document.write('<td width="210" weight="*%" bgcolor="#6C799B"
bordercolor="white" style="border-bottom-width:1px;
border-bottom-style:solid;">&nbsp;</td>');
document.write('<td width="*" height="*%" bgcolor="#C2C7D3"
bordercolor="white" style="border-width:1px; border-style:solid;">');
if (screen.width == 800) {
document.write('<div style="width:*%; height:100%; overflow:auto;
background-image:url(images/700/appropriate_filename_for_this_resolution.png);
background-repeat:no-repeat; background-position: 50% 50%; align:left;
text-align:justify">');
}
if ((screen.width > 800) && (screen.width <= 1000)) {
document.write('<div style="width:*%; height:100%; overflow:auto;
background-image:url(images/900/appropriate_filename_for_this_resolution.png);
background-repeat:no-repeat; background-position: 50% 50%; align:left;
text-align:justify">');
}
if ((screen.width > 1000) && (screen.width <= 1200)) {
document.write('<div style="width:*%; height:100%; overflow:auto;
background-image:url(images/1100/appropriate_filename_for_this_resolution.png);
background-repeat:no-repeat; background-position: 50% 50%; align:left;
text-align:justify">');
}
if ((screen.width > 1200) && (screen.width <= 1400)) {
document.write('<div style="width:*%; height:100%; overflow:auto;
background-image:url(images/1300/appropriate_filename_for_this_resolution.png);
background-repeat:no-repeat; background-position: 50% 50%; align:left;
text-align:justify">');
}
if ((screen.width > 1400) && (screen.width <= 1600)) {
document.write('<div style="width:*%; height:100%; overflow:auto;
background-image:url(images/1500/appropriate_filename_for_this_resolution.png);
background-repeat:no-repeat; background-position: 50% 50%; align:left;
text-align:justify">');
}
if (screen.width > 1600) {
document.write('<div style="width:*%; height:100%; overflow:auto;
background-image:url(images/1500/appropriate_filename_for_this_resolution.png);
background-repeat:no-repeat; background-position: 50% 50%; align:left;
text-align:justify">');
}
}

Now, the *.html file should call the javascript and provide it with
the appropriate filename to be shown in the respective resolution.

Maybe this is a stupid question and the approch might be quite simple,
but at the very moment I'm unable to think of a good solution.

Can anyone please help?
Sincerely

Markus Mohr

Jul 20 '05 #1
2 10384
Markus Mohr <ma*********@mazimoi.de> writes:
For every monitor resolution in 200 pixel steps from 800 to 1600
pixels I have an image to be shown as centered background-image.
Those images all have the same name and reside in the following
physical path structure:

/images/700/many_files_in_this_dir.png
/images/900/many_files_in_this_dir.png
/images/1100/many_files_in_this_dir.png
/images/1300/many_files_in_this_dir.png
/images/1500/many_files_in_this_dir.png

The basic idea is to selectively display the appropriate *.png file
for every *.html file to be opened on the website according to the
user's individual monitor resolution.
Why use monitor resolution if the browser isn't maximized?

If you insist on relying on resolution, at least use screen.availWidth
instead of screen.width.
Now, I could do this job easily in PHP oder Perl, but the customer
wants to have it in JavaScript.
That would require your server to know my screen resoltution, which
would require Javascript.

Some code snippet I have already tried to set up and show the basic
idea:

That's a lot of code for such a small thing.

var baseName="many_files_in_this_dir.png";
var fileSize;
if (screen.availWidth <= 800) {
fileSize = "700";
} else if (screen.availWidth <= 1000) {
fileSize = "900";
} else if (screen.availWidth <= 1200) {
fileSize = "1100";
} else if (screen.availWidth <= 1400) {
fileSize = "1300";
} else { // > 1400
fileSize = "1500";
}
var fullFileName = "images/"+fileSize+"/"+baseName;
document.write('<td width="*" height="*%" bgcolor="#C2C7D3"
bordercolor="white" style="border-width:1px; border-style:solid;">');
"*%" is not a valid value for the height attribute. Nor is "*" for the
width.
if (screen.width == 800) {
document.write('<div style="width:*%; height:100%; overflow:auto;
"*%" isn't valid as a CSS length either.

document.write('<div style="height:100%; overflow:auto;'+
'background: url('+fillFileName+') 50% 50% no-repeat;'+
'text-align:justify;">');

There is no CSS property called "align".
Now, the *.html file should call the javascript and provide it with
the appropriate filename to be shown in the respective resolution.


See above.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
On 29 Oct 2003 01:34:46 +0100, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
Markus Mohr <ma*********@mazimoi.de> writes:

[....]

That's a lot of code for such a small thing.

var baseName="many_files_in_this_dir.png";
var fileSize;
if (screen.availWidth <= 800) {
fileSize = "700";
} else if (screen.availWidth <= 1000) {
fileSize = "900";
} else if (screen.availWidth <= 1200) {
fileSize = "1100";
} else if (screen.availWidth <= 1400) {
fileSize = "1300";
} else { // > 1400
fileSize = "1500";
}
var fullFileName = "images/"+fileSize+"/"+baseName;


Thank you very much, that really does the job very well.

Sincerely
Markus Mohr
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jon W | last post by:
This is a small table with hover on the table cells. The first cell is setup to switch from div element to input element by use of display:block/none. In IE, onclick the input element is displayed...
0
by: Jon W | last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"> <html> <head> <title>rolly</title> <!-- The desired performance for this gem would be to: 1. click on table cells 2. edit in INPUT 3....
8
by: Emily Jones | last post by:
Very strange one this. Application written in Access 2000. Runs in 2003 at client's site, 2000 on my development system. FE/BE system. The app's startup form sets a few options, opens the...
2
by: JR | last post by:
Hi folks, How can I implement the following in C#? while(AppExitFlag == false) { if(AppPausedFlag == true) { GetMessage(); // Process messages.
6
by: nadeem_far | last post by:
Hello All, I am working on a .Net desktop application and I am having problem displaying a form. I am using C# and version 1.1 of the framework. here is how the code looks likes and I will...
1
by: Bernie Yaeger | last post by:
I have an mdi container that is opened max. Inside can be zero or dozens of child forms. One of the forms - my reporttree - is to be opened normal; all others maximized. When you have the...
1
by: Ingo Beyer | last post by:
Hello, I created a windows form with vs.net 2005 / c#. This control has a TabControl with 16 TabPages. On every TabPage there are a diffrent number of Controls. - Every TabPage has a background...
7
by: T J Rogers | last post by:
Hi folks, Below is a script that I use on a site to detect the size of the browser window then automatically load an alternative stile sheet when appropriate. Its a bit clumsy, and I don't...
1
by: Bill Gates | last post by:
Hello, I am creating oblique tabs for a webapp. It needs to be oblique tabs, and not regular tabs that you see in web browsers. Here's how it looks like: http://auriance.com/docs/interaction/ As...
1
by: Dave Rado | last post by:
Hi A while ago I discovered a way of creating css pseudo-frames, that offer users the important benefits of real frames (i.e. the navigation remains visible when you scroll down the page), but...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.