| method1: HTML knows percentage settings for WIDTH attributes e.g. <IMG WIDTH="60%" ...>
or for instance in
<TABLE WIDTH="100%" HEIGHT="100%">
<TR>
<TD ALIGN="center" VALIGN="middle">
<IMG SRC="http://www.itechies.net/hotscripts/images/itechies-logo.gif" WIDTH="80%">
</TD>
</TR>
</TABLE>
That the way the image is sized according to the current window's size
and is resized when the window is resized.
method2: An alternative way is to document.write the WIDTH as needed after checking the window dimensions:
var windowWidth = window.innerWidth ? window.innerWidth : document.body.clientWidth;
document.write(
'<IMG WIDTH="' + parseInt(0.6 * windowWidth) + '" ...>'
);
If you wanted to have the image resized on window resize you need to add
function reload () { window.location.reload(); }
window.onresize = reload;
IE also can assign expressions to style attributes which are reevaluted every time a subexpression changes so with IE
<IMG STYLE="width:expression(parseInt(0.6 *
document.body.clientWidth));" ...>
should be another way. |