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

122
Visualizações
I need move photo left and right using onclick event
let left = document.querySelector('#left');
let right = document.querySelector('#right');
let counter = 1;
let img_contant = document.querySelector('.img_contant');
let size = img_contant.clientWidth;

let increment = function () {
  img_contant.style = `margin-left: ` + counter * size +  `px`;
  counter++;
  console.log(counter);
}

let decrement = function () {
  img_contant.style = `margin-left: ` + counter * size + `px`;
  counter--;
  console.log(counter);  
}

left.addEventListener('click', decrement);

right.addEventListener('click', increment);
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

In your increment and decrement code, you are not using the style.marginLeft property which is intended. check the below code

let left = document.querySelector('#left');

let right = document.querySelector('#right');

let counter = 0;

let img_contant = document.querySelector('.img_contant');

let size = img_contant.clientWidth;

const increment = function () {
  counter++;
  img_contant.style.marginLeft = `${counter * size}px`;   
 }

const decrement = function () {
  counter--;
  img_contant.style.marginLeft = `${counter * size}px`;
 }

left.addEventListener('click', decrement);

right.addEventListener('click', increment);
<button id="left"> Left </button>
<button id="right"> Right </button>
<div>
<img class="img_contant" src="https://st.depositphotos.com/1000459/2436/i/450/depositphotos_24366251-stock-photo-soccer-ball.jpg" height = 200 width = 200 />
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Style attributes are converted from dash-case to camelCase for the style property.

img_contant.style.marginLeft = counter * size + 'px';

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