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

185
Vistas
How do console.log only (1 times) on mutation observer tracking inline style change?

I have written code below and basically grabs the element that is a scroll slide on a e-commerce website that changes its inline style attribute transform property every few second to slide the slideshow of images from left to right.

I want to observe the mutation change but only fire console.log (1 time) when it detects style attribute transform property change but I have problem. It is firing 40 - 50 times as the scroll slide change transform translate in x direction every 100 or pixels so mutation observer detects the change as 40 - 50 changes

how do i solve this issue of only having output console.log once and not 40-50 times. The scroll slide is also doing it continuously after page load every few seconds too.

  var styleMutate = function(mutations, observer) {
    mutations.forEach(function(mutationRecord) {
      if(mutationRecord.attributeName === 'style') { 
        //fireGaEvent('Image gallery scrolls to the right');
        console.log("style change");
        console.log(mutationRecord);
      }
      observer.disconnect();
    });
  };

  var observer = new MutationObserver(styleMutate);

  var target = document.getElementsByClassName('touchcarousel-container')[0];
  observer.observe(target, { attributes : true, attributeFilter : ['style']});
about 4 years ago · Juan Pablo Isaza
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