Foros del Web » Programando para Internet » Jquery »

Problemas con animate de jQuery

Estas en el tema de Problemas con animate de jQuery en el foro de Jquery en Foros del Web. Hola compañeros, intento hacer que un recuadro baje al evento click y vuelva a su posicion inicial al sacar el mouse fuera de ese recuadro ...
  #1 (permalink)  
Antiguo 07/12/2011, 18:22
 
Fecha de Ingreso: enero-2010
Mensajes: 389
Antigüedad: 14 años, 3 meses
Puntos: 4
Problemas con animate de jQuery

Hola compañeros,

intento hacer que un recuadro baje al evento click y vuelva a su posicion inicial al sacar el mouse fuera de ese recuadro o capa.

Lo estoy haciendo con .animate() de jQuery, el recuadro se desplaza para abajo al hacer click pero de seguido vuelve a su posicion pese a que no saco el mouse del recuadro y el z-index está al máxmo en mi CSS.

Os paso el código para que lo testeeis y me comenteis si veis cual es el fallo o donde me equivoco.

Código PHP:
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="es" lang="es">
<
head>
    <
script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    <!--
        $(document).ready(function(){
            //Sesiones
            $('#registro').click(function(){
                $("#registro").animate({
                    top: "0px"
                }, 1000);
            });
            $('#registro').mouseout(function(){
                $("#registro").animate({
                    top: "-55px"
                }, 600);
            });
        });
    //-->
    </script>
</head>
<body style="margin:0;">
    <div style="background:#333;height:200px;width:600px;">
        <div id="registro" style="position:absolute;top:-55px;left:50px;width:177px;height:70px;z-index:9999;background:#FFF;">
            <p>Hola</p>
        </div>
    </div>
</body>
</html> 
Gracias de antemano ;)
  #2 (permalink)  
Antiguo 08/12/2011, 07:54
Avatar de chicohot20  
Fecha de Ingreso: mayo-2009
Mensajes: 388
Antigüedad: 14 años, 10 meses
Puntos: 43
Respuesta: Problemas con animate de jQuery

Código HTML:
Ver original
  1. <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="es" lang="es">
  2. <head>
  3.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
  4.     <script type="text/javascript">
  5.     <!--
  6.        $(document).ready(function(){
  7.            //Sesiones
  8.            $('#registro').click(function(){
  9.                $(this).animate({
  10.                    top: "0px"
  11.                }, 1000);
  12.            });
  13.            $('#registro').hover(function(){
  14.             },function(){
  15.                $(this).animate({
  16.                    top: "-55px"
  17.                }, 600);
  18.            });
  19.        });
  20.    //-->
  21.     </script>
  22. </head>
  23. <body style="margin:0;">
  24.     <div style="background:#333;height:200px;width:600px;">
  25.         <div id="registro" style="position:absolute;top:-55px;left:50px;width:177px;height:70px;z-index:9999;background:#FFF;">
  26.             <p>Hola</p>
  27.         </div>
  28.     </div>
  29. </body>
  30. </html>
  #3 (permalink)  
Antiguo 08/12/2011, 08:52
 
Fecha de Ingreso: enero-2010
Mensajes: 389
Antigüedad: 14 años, 3 meses
Puntos: 4
Respuesta: Problemas con animate de jQuery

Uau! gracias chicohot20

No comprendo el porqué de poner la parte del hover fuera de la primera función, lo metes en una nueva, ¿me podrías explicar esa parte? Está claro que ahí fallaba pero no comprendo el código

Por cierto, hay alguna manera en jQuery de limitar las acciones por segundo? por ejemplo se puede hacer varios clicks y sacar el mouse rápidamente y como es obvio hace el efecto tantas veces como se le haya dado.

Última edición por erxaca; 08/12/2011 a las 09:05
  #4 (permalink)  
Antiguo 08/12/2011, 09:53
Avatar de chicohot20  
Fecha de Ingreso: mayo-2009
Mensajes: 388
Antigüedad: 14 años, 10 meses
Puntos: 43
Respuesta: Problemas con animate de jQuery

Código HTML:
Ver original
  1. <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="es" lang="es">
  2. <head>
  3.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
  4.     <script type="text/javascript">
  5.     <!--
  6.        $(document).ready(function(){
  7.            //Sesiones
  8.            $('#registro').click(function(){
  9.                $(this).animate({
  10.                    top: "0px"
  11.                }, 1000);
  12.            });
  13.            $('#registro').hover(function(){
  14.             },function(){
  15.                $(this).stop(true).animate({
  16.                    top: "-55px"
  17.                }, 600);
  18.            });
  19.        });
  20.    //-->
  21.     </script>
  22. </head>
  23. <body style="margin:0;">
  24.     <div style="background:#333;height:200px;width:600px;">
  25.         <div id="registro" style="position:absolute;top:-55px;left:50px;width:177px;height:70px;z-index:9999;background:#FFF;">
  26.             <p>Hola</p>
  27.         </div>
  28.     </div>
  29. </body>
  30. </html>
Lee la documentacion:

http://api.jquery.com/hover/
http://api.jquery.com/stop/
  #5 (permalink)  
Antiguo 08/12/2011, 16:16
 
Fecha de Ingreso: enero-2010
Mensajes: 389
Antigüedad: 14 años, 3 meses
Puntos: 4
Respuesta: Problemas con animate de jQuery

Gracias chicohot20, me pondré a estudiarlo

Etiquetas: ajax, html, js
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:07.