CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignCSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 21st, 2003, 09:52 PM
subatta subatta is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 9 subatta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
return function value to CSS

Please look at the following code:

I want to return the name of a different file based on screen size. Works fine but I want to return the value of function to the CSS attribute, background-image in the <style> tags.
Tried some methods and searched. Nothing works!
Please Help!

<script language="JavaScript">
function filename()
{
switch (screen.width)
{
case 800:
return "masthead1.jpg";
break;
case 640:
return "masthead0.jpg";
break;
case 1024:
return "masthead2.jpg";
break;
default:
return "masthead1.jpg";
break;
}
}
document.writeln(filename());
</script>
<style type="text/css">
body
{
background-image:url("masthead1.jpg");
margin: 0em 0em 0em 0em;
}
</style>

Reply With Quote
  #2  
Old November 21st, 2003, 11:50 PM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 5
In DOM 2, you can manipulate style sheets:

http://www.csie.ntu.edu.tw/~b750605..._style_ref.html

So once you've checked for the client's screen width, you can set the appropriate image for background.
__________________
Hello, old friend...

Reply With Quote
  #3  
Old November 21st, 2003, 11:57 PM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 5
Fooling around with it, I finally got this to work:

Code:
<html>
<head>
	<title>change CSS</title>

	<style type="text/css">  /* this would be styleSheet.item(0) */
	html, body {width:800px;}  /* this would be rules.item(0) */
	</style>
	
</head>

<body>

	<script type="text/javascript">
	var ss = document.styleSheets.item(0);
                var rules = ss.cssRules || ss.rules;

	rules.item(0).style.background = 'url(\'masthead1.jpg\')';  // here's where I set the bg image
	</script>

</body>
</html>

Reply With Quote
  #4  
Old November 22nd, 2003, 07:19 AM
subatta subatta is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 9 subatta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am trying something like this and can't get it to work :-) What am i doing wrong?

<html>
<style type="text/css">
body
{width:640px;
width:800px;
width:1024px;
margin: 0em 0em 0em 0em;
}
</style>

<body>
<script type="text/javascript">
var ss = document.styleSheets.item(0);
var rules = ss.cssRules || ss.rules;
switch (screen.width)
{
case 800:
rules.item(1).style.background = "url('masthead1.jpg')";
break;
case 640:
rules.item(0).style.background = "url('masthead1.jpg')"; // here's where I set the bg image
break;
case 1024:
rules.item(2).style.background = "url('masthead1.jpg')"; // here's where I set the bg image
break;
default:
rules.item(1).style.background = "url('masthead1.jpg')"; // here's where I set the bg image
break;
}
</script>
</body>
</html>

Reply With Quote
  #5  
Old November 22nd, 2003, 10:45 AM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 5
for starters, all of your cases should be rules.item(0)

then, I forgot to eliminate the width attribute. Just leave the rule empty, like this:

body {}

because your screen width will determine that.

next, you have to change the filename for each image, depending on the screen width. Right now, they all say masthead1.jpg



Quote:
Originally posted by subatta
I am trying something like this and can't get it to work :-) What am i doing wrong?

<html>
<style type="text/css">
body
{width:640px;
width:800px;
width:1024px;
margin: 0em 0em 0em 0em;
}
</style>

<body>
<script type="text/javascript">
var ss = document.styleSheets.item(0);
var rules = ss.cssRules || ss.rules;
switch (screen.width)
{
case 800:
rules.item(1).style.background = "url('masthead1.jpg')";
break;
case 640:
rules.item(0).style.background = "url('masthead1.jpg')"; // here's where I set the bg image
break;
case 1024:
rules.item(2).style.background = "url('masthead1.jpg')"; // here's where I set the bg image
break;
default:
rules.item(1).style.background = "url('masthead1.jpg')"; // here's where I set the bg image
break;
}
</script>
</body>
</html>

Reply With Quote
  #6  
Old November 22nd, 2003, 11:12 AM
subatta subatta is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 9 subatta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Done!

Thank you.

I was in a hurry to get out and by the time I got back I figured my mistakes and saw your angel advice.

Thanks once again!

Reply With Quote
  #7  
Old November 22nd, 2003, 11:13 AM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 5
np, glad I could help.

Reply With Quote
  #8  
Old November 22nd, 2003, 08:29 PM
subatta subatta is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 9 subatta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
it's me again.

Any way i can return a function's value to an attribute like..

<frameset border="0" cols="*,fwidth();">

I want to set the width of frames based on screen size like before.

Reply With Quote
  #9  
Old November 22nd, 2003, 09:53 PM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 5
For that, you would need setAttribute: (DOM level 1)

http://msdn.microsoft.com/library/d...etattribute.asp

You're in luck, it applies to <FRAMESET>.

Example of syntax: http://www.mozilla.org/docs/dom/dom...m_el_ref57.html

Last edited by khwang : November 22nd, 2003 at 09:56 PM.

Reply With Quote
  #10  
Old November 22nd, 2003, 10:37 PM
subatta subatta is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 9 subatta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I found this link with the clue you provided by a search on google:

http://dev.eclipse.org/viewcvs/inde...lp.jsp?rev=1.16

and adapted the code to work with my requirements. No luck :-(

Please see the code.. i really appreciate your input.


------------------------------------------------------
<html>
<head>
<script type="text/javascript">
var fs1 = document.getElementById('main1');
var fs2 = document.getElementById('main2');
function resizeme()
{
switch (screen.width)
{
case 640:
fs1.setAttribute("cols", "*,72.4%");
fs2.setAttribute("cols", "*,72.4%");
break;
case 800:
fs1.setAttribute("cols", "*,76.4%");
fs2.setAttribute("cols", "*,76.4%");
break;
case 1024:
fs1.setAttribute("cols", "*,80.4%");
fs2.setAttribute("cols", "*,80.4%");
break;
default:
fs1.setAttribute("cols", "*,76.4%");
fs2.setAttribute("cols", "*,76.4%");
break;
}
}
</script>
</head>
<frameset border="0" rows="20%,70%,10%">
<frame noresize="noresize" src="header.htm">
<frameset id="main1" border="0" cols="*,76.4%">
<frame noresize="noresize" src="nav.htm">
<frame noresize="noresize" src="main.htm" name="showframe">
</frameset>
<frameset id="main2" border="0" cols="*,76.4%">
<frame noresize="noresize" src="footer.htm">
<frame noresize="noresize" src="defaultfooter.htm" name="showfooter">
</frameset>
</frameset>
<body></body>
</html>

Reply With Quote
  #11  
Old November 23rd, 2003, 12:28 AM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 5
I couldn't get it to work with FRAMESET, but your code did work with a regular TABLE:

Code:
<html>
<head>
	<title>setAttribute test</title>
	
</head>

<body>

<table border="1">
<tr>

<td id="main1">stuff stuff stuff stuff stuff 
stuff stuff stuff stuff stuff stuff stuff stuff 
stuff stuff stuff stuff stuff stuff stuff stuff 
stuff stuff stuff stuff stuff stuff stuff stuff 
stuff stuff stuff stuff stuff stuff stuff stuff 
stuff stuff stuff stuff stuff stuff </td>
<td id="main2">stuff 2 stuff stuff stuff 
stuff stuff stuff stuff stuff stuff stuff 
stuff stuff stuff stuff stuff </td>

</tr>
</table>

<script type="text/javascript">
var fs1 = document.getElementById('main1');
var fs2 = document.getElementById('main2');

switch (screen.width)
{
case 640:
fs1.setAttribute("width", "416");
fs2.setAttribute("width", "200");
break;
case 800:
fs1.setAttribute("width", "576");
fs2.setAttribute("width", "200");
break;
case 1024:
fs1.setAttribute("width", "800");
fs2.setAttribute("width", "200");
break;
default:
fs1.setAttribute("width", "75%");
fs2.setAttribute("width", "25%");
break;
}
</script>

</body>
</html>


I'll keep plugging away with it, but I must ask: why do you want frames? I thought maybe you wanted to keep the left-hand frame at a constant width, but the percentages don't match up.

Reply With Quote
  #12  
Old November 23rd, 2003, 09:19 AM
subatta subatta is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 9 subatta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
if the left hand frame is navigation frame where i have a java menu. Since it is beyond my intel to try resizing it to screen res, I am trying to fit it in the left frame.

I tried the fixed width idea but it looks the java menu is resizing to screen res, so i am forced to resize the frame it is in.

I cannot use a table since pages loaded into content frame to the left are individual pages. the design was so..

I think i will just fix the frame at 800x600 and forget the inconsistancy at 640x480.. works fine at 1024..

In short, i am giving up and compromising.. I hope users will not complain.

It is actually a browser app for a book. so, frames were chosen since different pages are loaded for navigation, content and footnotes.

I really appreciate your input and i hope to keep this wonderful realtionship(god knows what they call it). It really helps to be in touch with experts like you.

Reply With Quote
  #13  
Old November 23rd, 2003, 09:52 AM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 5
I'm no expert, since I did not actually solve your problem.

But I do think it's a good idea to go with 800 x 600, I see a lot of top e-commerce sites have adopted that approach.

Be sure to post a link here, when it's done.

Quote:
Louis, I think this is the beginning of a beautiful friendship.

Reply With Quote
  #14  
Old November 25th, 2003, 02:34 PM
subatta subatta is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 9 subatta User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
navigation question

Hi, it's me again.

This time it's a navigation q.

I have a footer page for every content page that is loaded on body load of content page each in their own frames.
Problem is, when i use history.go(-1), i go to footer page. If i use -2, it is getting erratic and ending up on footer pages.

Any way i can solve this..

given thought of retrieving filename from history but no such methods in javascript that i know..

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignCSS Help > return function value to CSS


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump