Solved

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

Posted on 2006-11-05
3
1,370 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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
key press alert 2 32
jquery datable hidden section doesn't submit 2 15
Access RV042 GUI / Browser Issues 25 47
html input 8 42
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

809 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