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

177
Vistas
How not to get spammed with mouseover and mouseout (by time)?

https://jsfiddle.net/0bt3hy29/6/

function chandgeBackgroundImageOnMouse() {
    house.addEventListener("mouseover", ()=>{
        bgImage.style.backgroundImage = home
        is_paused = true
})
    house.addEventListener("mouseout", ()=>{
        is_paused = false
    })
}

When you mouseover the "house" element and then mouseout it - everything is working as should. But if you will mouseover and mouseout very quickly - auto slider will be broken.

So, i see 2 choises.

  1. To make react only after a gap of 3 seconds (it's mouseover and then mouseout - only after 3 seconds it can be mouseover one more time)

  2. To make react only when picture was changed (it's mouseover, then mouseout - and only after picture was changed it can be mouseover one more time)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your code is recursive with interval so its recursvevly creating new instances of many things. Instead, try this.

    const car = "url('https://images.unsplash.com/photo-1580273916550-e323be2ae537?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=464&q=80')"
const home = "url('https://images.unsplash.com/photo-1600596542815-ffad4c1539a9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1175&q=80')"
const candles = "url('https://images.unsplash.com/photo-1593542468714-ac3ba4b38d43?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1169&q=80')"
const data = [
car,
home,
candles,
]

const house = document.querySelector('#house')
const avto = document.querySelector('#avto')
const bgImage = document.querySelector('.img-of-dog')

let current = 0;

function intervalMethod(){
        bgImage.style.backgroundImage = data[current]
        current = ++current % data.length
}

let changeTimeset = setInterval(()=>{
        intervalMethod();
    }, 2000)
  
  
house.addEventListener("mouseover", ()=>{
     clearInterval(changeTimeset);
          bgImage.style.backgroundImage = home
    })
house.addEventListener("mouseout", ()=>{
     changeTimeset = setInterval(()=>{
        intervalMethod();
         }, 2000)
        })
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