Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/07/2011, 12:13
Avatar de Naahuel
Naahuel
 
Fecha de Ingreso: marzo-2011
Ubicación: localhost
Mensajes: 796
Antigüedad: 13 años, 1 mes
Puntos: 192
Respuesta: Ejecutar sentencia mientras permanezca en hover

En estos caso viene bien un plugin:
http://plugins.jquery.com/project/Pa...sume-animation

Ese plugin permite pausar y resumir una animación. Ejemplo:
http://jsbin.com/aleheg/2 (Mirá en "edit" para ver el código. Lo que sale a la izquierda es el plugin).

Otra forma (Que puede ser mejor, pues nos evitamos el uso de plugins y además es más personalizable) es usar .stop() y .animate() con un correcto uso de .mouseenter() y .mouseleave(), haciendo que la velocidad sea lenta:
http://jsbin.com/aleheg/3

Código:

Código HTML:
Ver original
  1. <!DOCTYPE html>
  2. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
  3.   <script>
  4.    $(document).ready(function () {
  5.  
  6.      $('#hello').mouseenter(function(){
  7.        _animarDiv($('#moveme'));
  8.      })
  9.        .mouseleave(function(){
  10.        _detenerAnimacion($('#moveme'));
  11.      });
  12.      
  13.      //funcion para animar
  14.     function _animarDiv(_elem){
  15.       var velocidad = 80000;//velocidad muy baja
  16.       var topActual = _elem.offset().top;
  17.       _elem.animate({
  18.         top: topActual + 10000//animar propiedad TOP
  19.       },velocidad,'linear');//easing "linear", pero puede ser otro
  20.      }
  21.      
  22.      //funcion para detener animacion
  23.      function _detenerAnimacion(_elem){
  24.      _elem.stop();
  25.      }
  26.      
  27.     });
  28.   </script>
  29.   #moveme{
  30.     position:fixed;
  31.     right:0;
  32.     top:0;
  33.     width:100px;
  34.     height:100px;
  35.     background:yellow;
  36.   }
  37. </head>
  38.   <p id="hello">Mover el div</p>
  39.   <div id="moveme"></div>
  40. </body>
  41. </html>
__________________
nahueljose.com.ar