I have a div 1024 x 768 px. I want show center a 1920 x 1080 px image right in the middle of the div and continue to be visible with scrolling div.
How can it be done?
Here is the Test code.
var el = document.querySelector('div.mainDiv');
var newWidth = Math.ceil($("#baseImg").width()/2);
var newHeight = Math.ceil($("#baseImg").height()/2);
el.scrollLeft = newWidth;
el.scrollTop = newHeight;
<!-- begin snippet: js hide: false console: true babel: false -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="mainDiv">
<img id="baseImg" src="https://dummyimage.com/1920x1080/000/fff">
</div>
.mainDiv {
margin: 0 auto;
width: 1042px;
height: 768px;
overflow: scroll;
}
.mainDiv img {
width: 1920px;
height: 1080px;
}
<div class="mainDiv">
<img src="https://dummyimage.com/1920x1080/000/fff">
</div>
---EDIT---
I solve the problem with some code of javascript
var el = document.querySelector(element);
var newWidth = Math.ceil($(elementId).width()/2);
var newHeight = Math.ceil($(elementId).height()/2);
el.scrollLeft = newWidth;
el.scrollTop = newHeight;