Solved

resize images to 100% width, keep height in proportion?

Posted on 2006-11-05
3
1,376 Views
Last Modified: 2012-06-21
Hi,
I'm trying to show an image or a swf (depending on whether the user has flash) inside a browser window that has been already resized to full screen width and height.

The image & swf are 2:1 proportions, and I need to find a way to display them at 100% width, and to set the height to half of the height.

I have some of the pieces, but can't connect them...

for example var imgWidth = screen.availWidth; and var imgHeight = imgWidth / 2; gives me the height & width I want, but how do I write javascript variables inside an html tag?

ie <img src="images/abc.jpg" width="imgWidth" height="imgHeight"> - how do I write the width & height variables here?

thanks...



0
Comment
Question by:hc0904pcd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
DireOrbAnt earned 500 total points
ID: 17878569
document.write('<img src="images/abc.jpg" width="'+imgWidth+'" height="'+imgHeight+'">');

However that's not the best way. Best way is to stick an img tag with an id like id="MyImg"
Then:
document.getElementById('MyImg').width = imgWidth;
document.getElementById('MyImg').height = imgHeight;
0
 
LVL 6

Author Comment

by:hc0904pcd
ID: 17879753
thanks, that's exactly what i needed :)
0
 
LVL 26

Expert Comment

by:DireOrbAnt
ID: 17882953
:)
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question