Ver Mensaje Individual
  #5 (permalink)  
Antiguo 23/02/2011, 16:42
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

Bueno ya conseguí solucionarlo para FF y Chrome, pero como siempre IE da problemas
El código está así:
Código Javascript:
Ver original
  1. // Le añadí la opción de ponerle tiempo
  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];
  5.    var n = cuanto - P(this).getStyle(resta).Numeros();
  6.    var estilo = P(this).css('position', 'absolute').css(resta, P(this).getStyle(resta)).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, en IE me da error en la función posicion :
Código Javascript:
Ver original
  1. // ...
  2.   posicion : function(donde){
  3.    var left = this.offsetLeft, top = this.offsetTop, padre = this.offsetParent, body = P(document.body);
  4.    while(!/(body|html)/i.test(padre.tagName)){
  5.     left += padre.offsetLeft;
  6.     top += padre.offsetTop;
  7.     padre = padre.offsetParent;
  8.    }
  9.    return {
  10.     'left' : left,
  11.     'right' : body.getStyle('width').match(/\d+/)[0]-left,
  12.     'top' : top,
  13.     'bottom' : body.getStyle('height').match(/\d+/)[0]-top
  14.    }[donde];
  15.   },
  16. // ...
Haciendo pruebas resulta que el error está en
Código Javascript:
Ver original
  1. 'right' : body.getStyle('width').match(/\d+/)[0]-left,
porque devuelve auto.
¿Cómo puedo averiguar cuánto mide el body (y todos los demás porque siempre me devuelve auto -.-') ?
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