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

Otra duda Ahora estoy haciendo una función que me mueva un elemento desde un lugar (left, top, right o bottom) n px. En principio no hay problema cuando el parámetro es left o top, pero con los otros dos sí. Posteo el código y os pediría que lo probaráis porque no sé explicar muy bien el problema XD :
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.   // el problema está en mover
  17.   mover : function(desde, cuanto){
  18.    var obj = { 'left' : 'right', 'top' : 'bottom', 'right' : 'left', 'bottom' : 'top' };
  19.    var estilo = P(this).css('height', P(this).getStyle('height')).css('width', P(this).getStyle('width')).posicion(desde);
  20.    return P(this).css('position', 'absolute').css(obj[desde], 'auto').css(desde, parseFloat(estilo + cuanto) + 'px');
  21.   },
  22. // ...
Saludos y gracias :D
__________________
" 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