I´m displaying an images 1000x1000px in a smaller div 320x460px with overflow:auto so you can scroll the image within the div. When I load the page then the image is displayed from the left-top corner off the image, and I wonder how I can display the image centered instead?
Any input appreciated, thanks.
Here is the code. In my index file I load the page like this:
$('#kartamap').load('imagemap.html', function() {
alert(".load has loaded");
imagescroll();
});
And this is my page.
<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>