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

260
Visualizações
How to use JS to move the box left and right

This is my css and html for the weight and arrows. I want to make the weight to move left and right by clicking arrows. Please help me to find js.

.container {
  width: 1050px;
  height: 200px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 255, 3.5, 0.4);
}
.arrow {
  top: 50%;
  transform: translate(0, -50%);
  position: absolute;
  font-size: 100px;
  cursor: pointer;
}
.right {
  top: 50%;
  transform: translate(0, -50%);
  position: absolute;
  font-size: 100px;
  cursor: pointer;
  right: 0;
}
.board {
  transform-origin: 50%, 50%;
  width: 1000px;
  height: 10px;
  background: #ff0;
  position: relative;
  top: 140px;
  left: 25px;
}
.weight {
  transform-origin: -50% -50%;
  width: 50px;
  height: 50px;
  background: #f00;
  position: relative;
  top: 140px;
  left: 500px;
}
<div class="container">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  <div class="arrow left"><i class="fas fa-chevron-left"></i></div>
  <div class="arrow right"><i class="fas fa-chevron-right"></i></div>
  <div class="scale">
    <div class="base"></div>
    <div class="gravity">
      <div class="weight"></div>
      <div class="board"></div>
    </div>
  </div>
</div>

I have HTML and CSS but would like to know to make jS how to make move this weight right and left by clicking the arrows.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try this:

HTML:

<div class="arrow left" onclick="arrowLeft"><i class="fas fa-chevron-left"></i></div>
<div class="arrow right" onclick="arrowRight"><i class="fas fa-chevron-right"></i></div>
<div class="weight" id="weight"></div>

JS:

var left = 0
var right = 0
function arrowLeft() {
   let x = document.getElementById("weight")
   left = left + 25 + "px"
   x.style.left = left;
}
function arrowRight() {
   let x = document.getElementById("weight")
   right = right + 25 + "px"
   x.style.left = right;
}
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