Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
scrollLeft scrolls to a not round px value

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

here is what it shows

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>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!