1000x1000px の画像を 320x460px の小さな div に overflow:auto で表示しているので、div 内で画像をスクロールできます。ページを読み込むと、画像が画像の左上隅から表示されますが、代わりに画像を中央に表示するにはどうすればよいでしょうか?
ご意見ありがとうございます。
これがコードです。私のインデックスファイルでは、次のようにページをロードします。
$('#kartamap').load('imagemap.html', function() {
alert(".load has loaded");
imagescroll();
});
そしてこれが私のページです。
<div id="themap">
<div id="imagediven" style="height:460px; width:320px;">
<img src="image.png" width="1000px" height="1000px"/>
</div>
<style>
#imagediven {
overflow:auto;
height:460px;
width:320px;
position:relative;
}
</style>
<script type="text/javascript">
function imagescroll(){
var element = document.getElementById('imagediven'), /* This is your div */
scrollHeight = element.scrollHeight,
scrollWidth = element.scrollWidth;
clientHeight =$(window).height();
clientWidth = $(window).width();
alert(scrollHeight);//this is not displaying the image height?
alert(clientHeight);//this is getting a value off the screen
element.scrollTop = (scrollHeight - clientHeight) / 2;
element.scrollLeft = (scrollWidth - clientWidth) / 2;
}
</script>
</div>