Dynamic resizing of images

M

Mike

I need to be able to set EITHER document.imageName.width OR
document.imageName.height to a specific value and then have the other
property set to it's default. For instance, if I was going to
hard-code all these images, some would look like <img src=blah
width=100> and some would look like <img src=blah2
height=100>. How do I "leave off" the second sizing parameter from
javascript. I've tried width='', width=0, width=null - none of these
work as they make the image have zero width.
 
G

Grant Wagner

Mike said:
I need to be able to set EITHER document.imageName.width OR
document.imageName.height to a specific value and then have the other
property set to it's default. For instance, if I was going to
hard-code all these images, some would look like <img src=blah
width=100> and some would look like <img src=blah2
height=100>. How do I "leave off" the second sizing parameter from
javascript. I've tried width='', width=0, width=null - none of these
work as they make the image have zero width.

I'm not sure what the problem is, if you don't want to change a particular
dimension of a particular image, just don't change it:

<body onload="setTestImageHeight();">
<script type="text/javascript">
function setTestImageHeight() {
document.images['testImage'].height = 200;
}
</script>
<img src="100by100.gif" name="testImage" />

After loading this page, the test image will be 200 pixels high and 100
pixels wide (assuming the browser supports dynamically resized images).

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 
R

Randy Webb

@SM wrote:

<p><a href="javascript:resizeImage('i04',500,'');">exo 1</a>
<p><a href="javascript:resizeImage('i04','',150);">exo 2</a>
<p><a href="javascript:resizeImage('i02','',50);">exo 3</a>

Perhaps you have not read the group FAQ? If you haven't, then you
should. URL is in my signature.
 
@

@SM

Mike a ecrit :
I need to be able to set EITHER document.imageName.width OR
document.imageName.height to a specific value and then have the other
property set to it's default. For instance, if I was going to
hard-code all these images, some would look like &lt;img src=blah
width=100&gt; and some would look like &lt;img src=blah2
height=100&gt;. How do I "leave off" the second sizing parameter from
javascript. I've tried width='', width=0, width=null - none of these
work as they make the image have zero width.

understood anything !

function resizeImage(img,width,height){
if(document.images){
i=document.images;
alert('image default width = '+i.width+
'\nimage default height = '+i.height);
if(width!='' && i.width!=width) i.width=width;
else
if(height!='' && i.height!=height) i.height=height;
}}

<img src="asm.gif" name="i04" width=50>
<img src="asm.gif" name="i02">
<p><a href="javascript:resizeImage('i04',500,'');">exo 1</a>
<p><a href="javascript:resizeImage('i04','',150);">exo 2</a>
<p><a href="javascript:resizeImage('i02','',50);">exo 3</a>

--
******** (enlever/remove [OTER_MOI] du/from reply url) *******
Stéphane MORIAUX : mailto:[email protected]
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
**************************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top