Skip to content Skip to sidebar Skip to footer

Resizing An Image Using Javascript Running In Opera Browser

I hope someone can help with this quirky issue I am having with the Opera Browser, I have version 11 Beta installed, but I suspect is a common problem in Opera. The website and pag

Solution 1:

instead of doing width and height attributes, I think you can just set width: 33% via CSS and have the scaling happen automatically, regardless of the browser window size. Better solution than trying to use javascript, IMHO.

Here's a simple tutorial: http://haslayout.net/css-tuts/CSS-Proportional-Image-Scale

Solution 2:

you are making this way too complicated. I don't think your issue is browser-specific, you just need to recode your script.

First. I would recommmend using percentages.. Not sure how you will guess the visitors browser width in pixels.

Let's say that your three resizeable images are 20% width of your browser. So your css would be:

#img1, #img2, #img3 {
  width: 20%;
}

now that your css says that your images are 20% of the total with, you're good to add some js. Keep in mind that the percentage will be that of its outer container.

<scripttype=text/javascript">functionresizeImages() {
     document.getElementById('img1').style.height = (document.body.clientHeight - 100) * 0.2;
     document.getElementById('img2').style.height = (document.body.clientHeight - 100) * 0.2;
     document.getElementById('img3').style.height = (document.body.clientHeight - 100) * 0.2;
  }
</script>

and most importantly.. call your function:

add this to your body tag:

<bodyonresize="resizeImages()">

boom.. you're done.

Post a Comment for "Resizing An Image Using Javascript Running In Opera Browser"