Ver Mensaje Individual
  #7 (permalink)  
Antiguo 26/02/2011, 15:38
Avatar de _cronos2
_cronos2
Colaborador
 
Fecha de Ingreso: junio-2010
Mensajes: 2.062
Antigüedad: 13 años, 10 meses
Puntos: 310
Respuesta: Problema al mover elemento

Muchas gracias @ZK, conseguí solucionarlo como dijiste:
Código Javascript:
Ver original
  1. // ...
  2.   mover : function(desde, cuanto, tiempo){
  3.    var obj = { 'right' : 'left', 'bottom' : 'top' }, str = desde in obj ? obj[desde] : desde, multip = str == desde ? 1 : -1;
  4.    var resta = { 'left' : 'width', 'top' : 'height' }[str], tam = P(this)['offset' + resta.capitalize()];
  5.    var n = cuanto - tam;
  6.    var estilo = P(this).css('position', 'absolute').css(resta, tam).posicion(str);
  7.    if(!tiempo){
  8.     return P(this).css(str, parseFloat(estilo + cuanto * multip) + 'px');
  9.    }else{
  10.     var incr = cuanto / (tiempo / 20), obj = P(this), timer = setInterval(function(){
  11.      if(obj.posicion(str) >= estilo + cuanto){
  12.       timer = clearInterval(timer);
  13.       return obj;
  14.      }else{
  15.       obj.css(str, parseFloat(obj.posicion(str) + incr * multip) + 'px');
  16.      }
  17.     }, 20);
  18.    }
  19.   },
  20. // ...
Sin embargo ahora se me plantea otra duda. ¿Cómo puedo hacer que al moverlo, rebote y vuelve hacia atrás? Algo como esto (al pasar por encima de los items del menú). He probado así pero ni se acerca XD
Código Javascript:
Ver original
  1. // ...
  2.   rebote : function(desde, cuanto, tiempo){
  3.    var este = P(this), inverso = {'left' : 'right', 'top' : 'bottom' };
  4.    var obj = { 'right' : 'left', 'bottom' : 'top' }, str = desde in obj ? obj[desde] : desde;
  5.    var resta = { 'left' : 'width', 'top' : 'height' }[str], tam = P(this)['offset' + resta.capitalize()];
  6.    var estilo = este.css('position', 'absolute').css(resta, tam).posicion(str);
  7.    var incr = (cuanto * 1.1 / (tiempo * 11/12)) * 20, timer = setInterval(function(){
  8.     if(este.posicion(str) >= estilo + cuanto * 1.1){ timer = clearInterval(timer); return este; }
  9.     else{
  10.      este.css(str, parseFloat(este.posicion(str) + incr) + 'px');
  11.     }
  12.    }, 20);
  13.    incr = (cuanto * -0.1 / (tiempo * 1/12)) * 20, timer = setInterval(function(){
  14.     if(este.posicion(inverso[desde] || obj[desde]) <= estilo + cuanto){ timer = clearInterval(timer); return este; }
  15.     else{
  16.      este.css(str, parseFloat(este.posicion(str) + incr) + 'px');
  17.     }
  18.    }, 20);
  19.   },
  20. // ...
Saludos!
__________________
" Getting older’s not been on my plans
but it’s never late, it’s never late enough for me to stay. "
Cigarettes - Russian Red