Resizing images depending on client's dimensions





0
Date Submitted Sat. Sep. 22nd, 2007 9:45 AM
Revision 1 of 1
Helper el_nokio
Tags "auto" | "client" | "image" | "javascript" | "resize"
Comments 0 comments
This is a very simple javascript - script, which can help us to resize any image (picture) included on our web-page "automatecally" by getting the visιtor's(client side) dimensions Height + Width and so changing the image proportionally .


<script language="javascript">

function startclock() {
setInterval(clockresizer,1000); // 1000 means a refresh every 1 sec
}

function clockresizer() {
document.getElementById("idpointer").style.width = document.body.clientWidth;
document.getElementById("idpointer").style.height = document.body.clientHeight;
}

function resizer()
 {
document.getElementById("idpointer").style.height = document.body.clientHeight;
document.getElementById("idpointer").style.width = document.body.clientWidth;
 }

</script>

 

<img id="idpointer" src="ekona.png" alt="image" title="image" > 
 

<body onload="javascript:resizer();startclock();" onresize="history.go(0)">
 
<html>

<head>

<script type="text/javascript" src="imgresizer.js"> </script>

</head>

<body onload="javascript:resizer();startclock();" onresize="history.go(0)">
<img id="idpointer" src="fsplanet3.png" alt="Ikona, Sta metra sas!" title="Ikona, sta metra sas!" >   

</body>

</html>

 
# ..where imgresizer.js = our javascript code .

# It works all right with IE 7, Opera 9.21 and Firefox 2.0.0.6 just on Firefox the browsers window, after the time scaled refresh seems to blink the image somehow..thats the only "bug" ..if someone has any idea on how to fix this just post a comment ;)

Thanks [bigsmile]
n ' hope to find it usefull ;)

[ el_nokio ]

john nokis

- " i think that i can think as randomly as i want to always so.. " - [ el_nokio ]

Comments

There are currently no comments for this snippet.

Voting

Votes Up


Votes Down