Hey all:
I have a div of a known size, 672px X 672px. In it I will display
images that are of unknown size. I have two simple functions that
shrink and center the image:
function shrink()
{
if (document.getEl ementById('righ t').height >=
document.getEle mentById('right ').width)
{
var newwidth = (( document.getEle mentById('right ').width * 672) /
document.getEle mentById('right ').height);
document.getEle mentById('right ').height = 672;
document.getEle mentById('right ').width = newwidth;
}
else
{
var newheight = (( document.getEle mentById('right ').height * 672) /
document.getEle mentById('right ').width);
document.getEle mentById('right ').width = 672;
document.getEle mentById('right ').height = newheight;
}
}
function center()
{
if ( document.getEle mentById('right ').height > 672)
{
document.getEle mentById('right ').style.top = '-' +
(Math.abs(docum ent.getElementB yId('right').he ight - 672)/2) + 'px';
}
else
{
document.getEle mentById('right ').style.top =
(Math.abs(docum ent.getElementB yId('right').he ight - 672)/2) + 'px';
}
if ( document.getEle mentById('right ').width > 672)
{
document.getEle mentById('right ').style.left = '-' +
(Math.abs(docum ent.getElementB yId('right').wi dth - 672)/2) + 'px';
}
else
{
document.getEle mentById('right ').style.left =
(Math.abs(docum ent.getElementB yId('right').wi dth - 672)/2) + 'px';
}
}
So, when I want to display my first image, I simply:
document.getEle mentById('right ').src = cr_images[0][0].src;
shrink();
center();
This works. However, when I want to change the image to another image
with a different size, it uses the previous images height and width. In
the html of the page I have an img tag which sources a 1px gif, without
specifying the height or width.
Is there some way to 'reset' the height and width, or read it from
something like document.getEle mentById('right ').src.height?
Help?
-CJL