Detectar cuando el cursor está quieto sobre un elemento por un tiempo determinado.

  • Autor Autor zcriptz
  • Fecha de inicio Fecha de inicio
zcriptz

zcriptz

1
Xi
Programador
Verificación en dos pasos activada
Suscripción a IA
Uso:
onOver(ELEMENTO, DELAY, FUNCION(ELEMENTO));

Demo: (Cambiará el color de fondo del DIV a azul cuando el cursor esté quieto sobre él durante 500ms)
Insertar CODE, HTML o PHP:
<script>
    addEvent = new Function('o', 'e', 'f', "return o.addEventListener ? o.addEventListener(e, f, 0) : o.attachEvent ? o.attachEvent('on'+e, f) : 0");
    onOver = new Function('o', 't', 'f', "return addEvent(o, 'mousemove', function(e){ e.toElement.overTimeout ? clearTimeout(e.toElement.overTimeout) : 0; e.toElement.overTimeout = setTimeout(function(){ f(e.toElement) }, t); }), addEvent(o, 'mouseout', function(e){ e.fromElement.overTimeout ? clearTimeout(e.fromElement.overTimeout) : 0; })");

    window.onload = new Function("return onOver(document.getElementsByTagName('div')[0], 500, function(o){ o.style.backgroundColor = 'blue' })");
</script>

<div style="width:300px;height:250px;background-color:red"></div>
 
Última edición:
Atrás
Arriba