Я только что создал небольшой тест-код, вы можете найти его здесь
http://paloula.de/test/width_002.html
Он отлично работает в Chrome / Windows, но не в том случае, если вы моделируете мобильный телефон в Chrome / Windows(например, Galaxy S5) или под мобильным телефоном Android с Chrome: страница прокручивается влево, но максимум scrollLeft не достигнут.
Это css?Это метатег?Расчет кажется правильным.
Есть идеи?Спасибо!
Полный код:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0"/>
<style>
* {
margin: 0;
padding: 0;
}
HTML {
display: block;
position: relative;
height:100%;
}
BODY {
display: block;
position: relative;
min-height: 100%;
/* overflow-y: scroll; */
}
</style>
</head>
<body id="body">
<div style="background-color: #FF0000; display: block; position: relative; width: 1700px; height: 50px;">
<div style="background-color: #0000FF; display: block; position: absolute; width: 50px; height: 50px; right: 0"></div>
<div style="background-color: #FF00FF; display: block; position: absolute; width: 50px; height: 50px; left: 0"></div>
</div>
<script>
var scrollWidth = document.documentElement.scrollWidth;
var clientWidth = document.documentElement.clientWidth;
var offsetWidth = document.documentElement.offsetWidth;
console.log(scrollWidth);
console.log(clientWidth);
console.log(offsetWidth);
var maxScrollLeft = scrollWidth - clientWidth;
console.log("maxScrollLeft " + maxScrollLeft)
setTimeout(function() {
window.scrollTo(maxScrollLeft, 0);
}, 1);
setTimeout(function() {
window.scrollTo(0, 0);
}, 500);
</script>
</body>
</html>