[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.4

Image resizing based on browser window's width

Asked by Maioneis in JavaScript, Scripting Languages, Web Development

Tags: Scripting, Web, Browser, Java

Hello, I need help with this page:

http://www.agrarioalbenga.it/Dovesiamo.html

I'm trying to have an image resizing itself if the browser windows is too small, and to accomplish that I followed this tutorial:

http://buildinternet.com/2009/07/quick-tip-resizing-images-based-on-browser-window-size

I have been using the script as explained but I always get the smaller image, no matter what resolution or browser window width Im using.

I have tested and it turns out the contentwidth variable always has zero stored in it.

So I get the big image only if I change 700 to 0, which is obviously no use at all. Can somebody check out the source of my webpage and help me? What am I doing wrong?

The relevant script is from line 219 down, but there may be something I'm missing in the rest of the page. I've already tried inserting the script in other portions of the page, but it was obviously for naught.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/Scheletro.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<link rel="shortcut icon" href="favicon.ico" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Istituto Professionale per l'Agricoltura e l'Ambiente &quot;Aicardi&quot;</title>
<!-- InstanceEndEditable -->
<style type="text/css"> 
<!-- 
body  {
	background: #555555;
	margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
	padding: 0;
	text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
	color: #000000;
	font-family: "Times New Roman", Times, serif;
	font-size: 100%;
} 
/* Tips for Elastic layouts 
1. Since the elastic layouts overall sizing is based on the user's default fonts size, they are more unpredictable. Used correctly, they are also more accessible for those that need larger fonts size since the line length remains proportionate.
2. Sizing of divs in this layout are based on the 100% font size in the body element. If you decrease the text size overall by using a font-size: 80% on the body element or the #container, remember that the entire layout will downsize proportionately. You may want to increase the widths of the various divs to compensate for this.
3. If font sizing is changed in differing amounts on each div instead of on the overall design (ie: #sidebar1 is given a 70% font size and #mainContent is given an 85% font size), this will proportionately change each of the divs overall size. You may want to adjust based on your final font sizing.
*/
.twoColElsLtHdr #container {
	width: 95%;  /* this width will create a container that will fit in an 800px browser window if text is left at browser default font sizes */
	background: #CFDFFF; /* the auto margins (in conjunction with a width) center the page */
	border: 1px solid #000000;
	text-align: left; /* this overrides the text-align: center on the body element. */
	margin-top: 0;
	margin-right: auto;
	margin-bottom: 0;
	margin-left: auto;
} 
.twoColElsLtHdr #header {
	background-color: #036;
	text-align: center;
	color: #FFF;
	height: 6em;
	padding-top: 0;
	padding-right: 10px;
	padding-bottom: 0;
	padding-left: 10px;
	border: thin solid #000;
} 
.twoColElsLtHdr #header h1 {
	margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
	padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
	text-align: center;
	color: #FFF;
	font-size: 130%;
} 
/* Tips for sidebar1:
1. Be aware that if you set a font-size value on this div, the overall width of the div will be adjusted accordingly.
2. Since we are working in ems, it's best not to use padding on the sidebar itself. It will be added to the width for standards compliant browsers creating an unknown actual width. 
3. Space between the side of the div and the elements within it can be created by placing a left and right margin on those elements as seen in the ".twoColElsLtHdr #sidebar1 p" rule.
*/
.twoColElsLtHdr #sidebar1 {
	float: left;
	width: 9em; /* top and bottom padding create visual space within this div */
	background-color: #036;
	padding-top: 15px;
	padding-right: 0px;
	padding-bottom: 15px;
	padding-left: 0px;
	margin: 0px;
	border-top-style: solid;
	border-right-style: solid;
	border-bottom-style: solid;
	border-left-style: solid;
	border-top-width: thin;
	border-right-width: thin;
	border-bottom-width: thin;
	border-left-width: thin;
}
.twoColElsLtHdr #sidebar1 h3, .twoColElsLtHdr #sidebar1 p {
	margin-left: 10px; /* the left and right margin should be given to every element that will be placed in the side columns */
	margin-right: 10px;
} 
/* Tips for mainContent:
1. If you give this #mainContent div a font-size value different than the #sidebar1 div, the margins of the #mainContent div will be based on its font-size and the width of the #sidebar1 div will be based on its font-size. You may wish to adjust the values of these divs.
2. The space between the mainContent and sidebar1 is created with the left margin on the mainContent div.  No matter how much content the sidebar1 div contains, the column space will remain. You can remove this left margin if you want the #mainContent div's text to fill the #sidebar1 space when the content in #sidebar1 ends.
3. To avoid float drop, you may need to test to determine the approximate maximum image/element size since this layout is based on the user's font sizing combined with the values you set. However, if the user has their browser font size set lower than normal, less space will be available in the #mainContent div than you may see on testing.
4. In the Internet Explorer Conditional Comment below, the zoom property is used to give the mainContent "hasLayout." This avoids several IE-specific bugs that may occur.
*/
.twoColElsLtHdr #mainContent {
	margin-top: 0;
	margin-right: 1.5em;
	margin-bottom: 0;
	margin-left: 10em;
	position: relative;
	left: 0.4em;
	top: -0.3em;
} 
.twoColElsLtHdr #footer {
	padding: 0 10px;
	border: medium groove #09F;
	background-color: #9CF;
} 
.twoColElsLtHdr #footer p {
	margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
	padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
	text-align: center;
} 
/* Miscellaneous classes for reuse */
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
	float: right;
	margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page */
	float: left;
	margin-right: 8px;
}
.clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain a float */
	clear:both;
    height:0;
    font-size: 1px;
    line-height: 0px;
}
--> 
</style><!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.twoColElsLtHdr #sidebar1 { padding-top: 30px; }
.twoColElsLtHdr #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head> 
<body class="twoColElsLtHdr"> 
<div id="container">
  <div id="header">
    <h1><span style="text-align: center"></span>Istituto Professionale per l'Agricoltura e l'Ambiente &quot;Aicardi&quot;</h1>
    <p>P.zza S.  Bernardino ⬠Albenga  ⬠Tel. 0182/543574  </p>
  </div>
  <div id="sidebar1">
    <ul id="MenuBar1" class="MenuBarVertical">
	  <li><a href="Index.html">Home Page</a>      </li>
	  <li><a href="#" class="MenuBarItemSubmenu">La Nostra Scuola</a>
	    <ul>
          <li><a href="News.html">News</a></li>
          <li><a href="Storia.html">Storia dell'Istituto</a></li>
<li><a href="Locali.html">Galleria Fotografica</a></li>
          <li><a href="Dovesiamo.html">Dove siamo</a></li>
          <li><a href="Trasporti.html">Come Raggiungerci</a></li>
</ul>
	  </li>
	  <li><a class="MenuBarItemSubmenu" href="#">Orientamento</a>
	    <ul>
	      <li><a href="Ruolo.html">Il ruolo del...</a>          </li>
	      <li><a href="DalleMedie.html">Dalle medie</a></li>
          <li><a href="Triennio.html">Triennio</a></li>
          <li><a href="Biennio.html">Biennio</a></li>
	    </ul>
      </li>
      <li><a href="#" class="MenuBarItemSubmenu">Segreteria</a>
        <ul>
<li><a href="OrariSegreteria.html">Orari</a></li>
<li><a href="Iscrizione.html">Iscrizione</a></li>
<li><a href="Pof.html">Pof</a></li>
</ul>
      </li>
      <li><a href="#" class="MenuBarItemSubmenu">Attivit&agrave; e Progetti</a>
        <ul>
          <li><a href="3Area.html">Terza area</a></li>
          <li><a href="Stradale.html">Educazione stradale</a></li>
          <li><a href="Gite.html">Gite di istruzione</a></li>
        </ul>
      </li>
      <li><a href="#" class="MenuBarItemSubmenu">Area genitori</a>
        <ul>
          <li><a href="CircGen.html">Circolari</a></li>
          <li><a href="Ricevimento.html">Ricevimento Parenti</a></li>
          <li><a href="PG.html">Area privata</a></li>
        </ul>
      </li>
      <li><a href="#" class="MenuBarItemSubmenu">Area studenti</a>
        <ul>
          <li><a href="CircStud.html">Circolari</a></li>
          <li><a href="OrarioClassi.html">Orario</a></li>
          <li><a href="PS.html">Area privata</a></li>
        </ul>
      </li>
      <li><a href="#" class="MenuBarItemSubmenu">Area docenti</a>
        <ul>
          <li><a href="CircDoc.html">Circolari</a></li>
          <li><a href="OrarioDoc.html">Orario</a></li>
          <li><a href="Modulistica.html">Modulistica</a></li>
          <li><a href="PD.html">Area privata</a></li>
        </ul>
      </li>
      <li><a href="Links.html">Collegamenti</a></li>
	</ul>
	<span style="color:white">
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </span>
  <!-- end #sidebar1 --></div>
  <!-- InstanceBeginEditable name="EditRegion3" -->
  <div id="mainContent"> 
	<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.js"></script>
	
	<script type="text/javascript">
	$(document).ready(function() {
	
		function imageresize() {
			var contentwidth = $('#content').width();
			if ((contentwidth) < '700'){
			    $('.fluidimage').attr('src','Images/ViaMichelinSmall.jpg');
			} else {
			    $('.fluidimage').attr('src','Images/ViaMichelin.jpg');
			}
		}
	
		imageresize();	
	
		$(window).bind("resize", function(){
			imageresize();
		});
		
	});
	</script> 
    <p><img class="fluidimage" src="Images/ViaMichelin.jpg" align="right"/>L'Istituto si trova ad Albenga in zona Vadino, in Piazza San Bernardino.</p>
    <p>L'edificio è parte di una struttura che comprende la caserma dei vigili urbani e la Chiesa di San Bernardino.</p>
    <p>Per informazioni su mezzi e trasporti pubblici, vedere la pagina <a href="Trasporti.html">Come Raggiungerci</a>.</p>
    <p>&nbsp;</p>
    <!-- end #mainContent -->
  </div>
  <!-- InstanceEndEditable -->
  <!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
  <div id="footer">
    <p><a href="http://www.iissgiancardigalileiaicardi.com/">ISTITUTO SECONDARIO SUPERIORE "GIANCARDI GALILEI AICARDI"</a></p>
  <!-- end #footer --></div>
<!-- end #container --></div>
<script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
//-->
</script>
</body>
<!-- InstanceEnd --></html>
 
Related Solutions
Keywords: Image resizing based on browser wind…
 
Loading Advertisement...
 
[+][-]11/04/09 11:15 AM, ID: 25742790Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: JavaScript, Scripting Languages, Web Development
Tags: Scripting, Web, Browser, Java
Sign Up Now!
Solution Provided By: mplungjan
Participating Experts: 1
Solution Grade: B
 
[+][-]11/04/09 12:53 PM, ID: 25743782Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/09 01:39 PM, ID: 25744241Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/09 11:06 PM, ID: 25747291Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 11:25 PM, ID: 25747366Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/09 11:30 PM, ID: 25747383Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 07:12 AM, ID: 25750265Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625