This javascript script resizes all image on the page, it can be controlled by the variable i and the greater than clause in the for loop. i=0 means it starts from the first image, change i=3 it will start from the forth image. The greater than clause will resize x amount of images. right now it resizes 10 images. The first 100 seen decides if the image is under 100 pixels wide not to resize it to 100, the second is what to resize the image too. comment any questions
<script language="javascript" type="text/javascript">
<!--
function resize_images()
{
for (i = 0; i < 10; i++)
{
while ( !document.images[i].complete )
{
break;
}
if ( document.images[i].width > 100 )
{
document.images[i].width = 100;
}
}
}
//-->
</script>
To implement the function on the page use this as your body tag
<body onLoad="resize_images()">
2 comments ↓
If you found this post useful click the share this button. Contribute below by adding a comment, no registration is required.
DCE Related Posts
Read Full Article...
This post teaches you how to replace CSS text links with an image and an image hover state. Read Full Article...
Nice simple script. Only iussue I have is an IE 7 script error which states:
Message: ‘document.images[...].complete’ is null or not an object
Any suggestions?
Do you have a link to where you are using it?
Leave a Comment