i use scrollLeft to scroll to the right 50px
but then i log the value of scrollLeft, it is 49.599998474121094px not 50px
how to make it scroll 50px
thanks for your support
function myFunction() {
var elmnt = document.getElementById("myDIV");
elmnt.scrollLeft += 50;
elmnt.scrollTop += 10;
document.getElementById ("demo").innerHTML = "Horizontally: " + elmnt.scrollLeft + "px<br>Vertically: " + elmnt.scrollTop + "px";
}
#myDIV {
height: 250px;
width: 250px;
overflow: auto;
}
#content {
height: 800px;
width: 2000px;
background-color: coral;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p>Click the button to scroll the contents of div by 50px horizontally and 10px vertically.</p>
<p><strong>Tip:</strong> Click the button many times to scroll the same amount each time.</p>
<button onclick="myFunction()">Scroll contents of div</button><br><br>
<div id="myDIV">
<div id="content">
Some text inside a div element.<br><br>
Some text inside a div element.
</div>
</div>
<p id="demo"></p>
</body>
</html>
Your Chrome browser window is most probably set to a zoom of 125% - which leads to this awkward result:
49.599998474121094px
Set the Zoom to 100% and there it is:
50px