Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/09/2017, 19:43
Avatar de ceaped
ceaped
 
Fecha de Ingreso: febrero-2004
Mensajes: 2.185
Antigüedad: 20 años, 2 meses
Puntos: 9
Pregunta drag and drop varia tamaño

Buenas noches
Tengo este ejemplo:

Código Javascript:
Ver original
  1. $(function(){
  2.             $('.box1').draggable({
  3.                 revert: 'invalid'
  4.             });
  5.             $('.box2').droppable({
  6.                 accept: '.box1',
  7.                 drop: function(event, ui){
  8.                     var $this = $(this);
  9.                     ui.draggable.position({
  10.                         my : "center",
  11.                         at : "center",
  12.                         of: $this,
  13.                         using: function(pos){
  14.                             $(this).animate(pos, 200, "linear");
  15.                         }
  16.                     });
  17.                 }
  18.             });
  19.            
  20.            
  21. function applyScale(element){
  22. var scale = $(element).attr('data-val');               
  23. $('.container').css({
  24. 'transform' : 'scale('+scale+')',
  25. 'transform-origin' : '0 0'
  26. });
  27. }
  28.            
  29. $("input[type='button']").on("click", function(i,e){
  30. applyScale($(this)[0]);
  31. });
  32.  
  33. });

Código CSS:
Ver original
  1. .container {
  2.     border: 1px solid #999;
  3.     position: relative;
  4.     width: 400px;
  5.     height: 400px;
  6.     margin: 0 auto;
  7.     background-color: #CCC;
  8.     }
  9.  
  10. .box {
  11.     color: #FFF;
  12.     position: absolute;
  13.     right: 0;
  14.     text-align: center;
  15.     background-color: #FF0000;
  16.     }
  17.  
  18. .box.box1 {
  19.     width: 80px;
  20.     height: 80px;
  21.     bottom: 0;
  22.     line-height: 80px;
  23.     z-index: 1;
  24.     background-color: #28ED48;
  25.     cursor: pointer;
  26.     }
  27.  
  28. .box.box2 {
  29.     background-color: #F3662F;
  30.     height: 100px;
  31.     left: 0;
  32.     line-height: 100px;
  33.     top: 0;
  34.     width: 100px;
  35.     z-index: 0;
  36.     }
  37.  
  38. input[type="button"] {
  39.     margin: 0 5px 5px 0;
  40.     }

Código HTML:
Ver original
  1. <input type="button" id="scale1" value="Apply Scale 0.5" data-val="0.5"></input>
  2.    
  3.     <input type="button" id="scale2" value="Apply Scale 1.5" data-val="1.5"></input>
  4.    
  5.     <input type="button" id="scale0" value="Apply Scale 1" data-val="1"></input>
  6.    
  7.     <div class="container">
  8.         <div class="box box1">1</div>
  9.         <div class="box box2">2</div>
  10.     </div>

Cuando varía la escala el centro del box al arrastrarse al otro box cambia.

¿Cómo hago para que siempre al arrastrar el box no se desajuste su centro?.

Gracias por su ayuda
__________________
Diseñador Gráfico publicitario