Resizing images depending on client's dimensions
0
el_nokio
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>
<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 . <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>
# 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 ]






There are currently no comments for this snippet.