Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

106
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda