-
I want to dynamically set the height and width of an image using javascript so that the image looks proportionally fine according to different screen resolutions..
The original image is of 252*62 pixels..
I have used the following code..but it doesnt seem to work.
Code:
<script type="text/javascript">
function resizeheight() {
var height = ((62*screen.height)/800);
return height;
}
function resizewidth() {
var width = ((252*screen.width)/1280);
return width;
}
HTML Code:
<img id="enter" src="enter.PNG" height="resizeheight()" width="resizewidth()" >
-
I got to know that we can't embed javascript calls like for the height and width attributes of an image.
Used another method. It worked. :)
Code:
<img id="enter" src="enter.PNG" alt="enter" />
<script type="text/javascript">
target=document.getElementById('enter');
target.style.width=((252*screen.width)/1280)+'px';
target.style.height=((62*screen.height)/800)+'px';
</script>