ブラウザの幅/高さに合わせてサイズを変更するシンプルな画像ビューアを作成しようとしています。私はもうすぐそこにいると思います。ただし、これを完了する方法についてのヒントが必要です。これがコードです。私はこれをできるだけシンプルで軽量にしようとしているので、jqueryを使いたくありませんでした。
ありがとう、MK
<style type="text/css">
body {
background-color: #999;
}
#fullscreenPhoto {
border: thin solid #F00;
}
</style>
<body onresize="resizeImage()">
<div onload="resizeImage()" margin="0" border="0" id="fullscreenPhoto">
<img src="resizeImage.jpg" width="100%" >
</div>
<script type="text/javascript">
var divResize = document.getElementById('fullscreenPhoto');
function resizeImage()
{
var window_height = document.body.clientHeight
var window_width = document.body.clientWidth
var image_height = divResize.offsetHeight
var image_width = divResize.offsetWidth
var height_ratio = image_height / window_height
var width_ratio = image_width / window_width
if (height_ratio > width_ratio)
{
divResize.style.width = "auto"
divResize.style.height = "100%"
}
else
{
divResize.style.width = "100%"
divResize.style.height = "auto"
}
}
</script>
</body>