QUOTE: Originally posted by Kornkob
Woudl it be practical for me to duplicate the width requirement lines of code with height requirement so that both dimensions are size restricted? |
|
I wouldn't set both at the same time. Your image will become distorted. Either set the width or the height and let the browser adjust the other proportionately. To do this, you would want to check which one is the larger of the two -- the width or the height. Then adjust accordingly.
The following code should do that. You'll need to change the variables to the max width and max height you want to allow for the site.
Hope that helps!
[code]
<SCRIPT LANGUAGE="JavaScript">
<!--
// Set the Maximum Width and Height
var maxImageWidth = 350;
var maxImageHeight = 350;
function resizeImage(thisimage) {
if (thisimage.height > thisimage.width) {
// check and modify height if needed
if (thisimage.height > maxImageHeight) {
thisimage.height = maxImageHeight;
thisimage.style.cursor='hand';
}
} else {
// check and modify width if needed
if (thisimage.width > maxImageWidth) {
thisimage.width = maxImageWidth;
thisimage.style.cursor='hand';
}
}
}
// End -->
</script>
[/code]
Oh, if you have a lot of scripts on your site, you might want to move the var statements inside the function itself to avoid any conflicts between variables (variable scope).