Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda