I'm developing a portfolio page, the grid containing the images it's dynamic so on certain mobile phone when changing orientation some images will distort the Width*Height ratio and it will get fixed only refreshing the page. For solving this problem I decided to put a Javascript code (that I got from this site) that will refresh the page when the orientation changes.
The problem is that when the page reload from THAT code it will lose the scrolling position and return at the top of the page, it will mantain the scrolling position if I reload manually with CTRL+R or using the refresh button, so I'm guessing that the problem it's in how the javascript code reload the page. Can you help me mantaining the scrolling position after reloading the page when the orientation on mobile changes?
I'm a total noob with almost zero knowledge about javascript and PHP. I've tried searching on internet for a solution but i can't figure it out.
Thank you
<script type="text/javascript">
window.onorientationchange = function() {
var orientation = window.orientation;
switch(orientation) {
case 0:
case 90:
case -90: window.location.reload();
break;
}
};
</script>