lucy24

msg:4394194 | 11:22 pm on Dec 4, 2011 (gmt 0) |
Tangential question: What are you doing here? var image_height = img.style.height; if(image_height <= window_height / 100 * 70) { image_height = window_height / 100 * 80 + "px"; } else { image_height = window_height / 100 * 80 + "px"; } |
| That is, what's happening in the if/then loop that wouldn't happen equally well with the single line var image_height = window_height * .8 ? (Setting aside the "px" issue because the midstream change from number to string makes me nervous.) | this works if i get elementbyid for the images but since id is a unique value it works only for the first image. |
| Will getElementsByName (plural) work? I ask this with hesitation because separating name from id also makes me nervous ;) Or even ...TagName if you're resizing all images. Do you have an earlier routine that makes sure the window_height is returning a valid number, and sets a default number if not? :: wandering off to perform further experiments on Tristram Shandy ::
|
erkutacar

msg:4394202 | 11:50 pm on Dec 4, 2011 (gmt 0) |
lol i obviously sent u one with 80 value just to see if it worked but i forget to change the first 70.. what i wanted to do was image height is equal to window height divided by hundred and multiplied by 70... if u can just type me a script that will do that for all the images inside the id'gallery' or images classed=whatever would be really helpful :D
|
birdbrain

msg:4394313 | 10:02 am on Dec 5, 2011 (gmt 0) |
Hi there erkutacar, and a warm welcome to these forums. ;) here is the script that you desire... <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <base href="http://www.webmasterworld.com/theme/default/gfx/"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="language" content="english"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript">
<title></title>
<style type="text/css"> img{ border:1px solid #000; } </style>
<script type="text/javascript">
function resize_images(){
var gallery=document.getElementById('gallery'); var img=gallery.getElementsByTagName('img'); var window_height=document.getElementsByTagName('html')[0].clientHeight;
for(var c=0;c<img.length;c++) { if(img[c].offsetHeight<=window_height*0.7) { img[c].style.height=window_height*0.7+'px'; } else { img[c].style.height=window_height*0.7+'px'; } } }
window.onresize=function() { resize_images(); } window.addEventListener? window.addEventListener('load',resize_images,false): window.attachEvent('onload',resize_images); </script>
</head> <body>
<div id="gallery"> <img src="wilk.gif" alt=""> <img src="happy.gif" alt=""> <img src="sad.gif" alt=""> </div>
</body> </html>
|
| birdbrain
|
|