0

我正在使用jQuery UI来允许一个类的元素。不过,我希望当其中一个被拖动的时候,一个类的其他元素可以遵循。我怎样才能做到这一点?当拖动一个类时拖动类的所有元素(jQuery UI可拖动)

所以当一个人被拖动时,其余的课也被拖动。

我试图在元素上的stop事件上触发mousedown,这样当其中一个元素被拖动时,拖动就会发生在其他元素上。

$('.dismissAllButton').draggable({ axis:'x', containment:'parent', start:function(){ upEvent = false; $(this).mousedown(); }, drag: function(){ $(this).mousemove(); }, stop:function(){ $(this).mouseup(); setTimeout(function(){ upEvent = true; }, 1000); }}); 

我也试图使自己的父母,这样其他人也将被拖入/跟踪时,其中一人被拖动,但没有奏效。

$('.dismissAllButton').draggable({ axis:'x', containment:'parent', handle:'.dismissAllButton', start:function(){ upEvent = false; }, stop:function(){ setTimeout(function(){ upEvent = true; }, 1000); }}); 

小提琴:

否下文中,仅一个元件拖动:http://jsfiddle.net/7ta68xyt/

试图1,上面的代码示例1,:http://jsfiddle.net/7ta68xyt/1/

尝试2,上面的代码示例2,:http://jsfiddle.net/7ta68xyt/2/

更新:我在github上发现了一个允许这样的脚本,但是其他呃元素都落后了一点。我怎么才能让它们在间隔时间内滞后,并在拖动停止时将它们拖到相同的地方,或者让它们都拖动相同(无滞后)。

这里是小提琴:http://jsfiddle.net/7ta68xyt/3/

下面是脚本:https://github.com/javadoug/jquery.drag-multiple

+0

你如何想像其他元素的拖动一个选项,他们是否会从目前的位置移动并跟随鼠标移动,还是会像蛇一样跟随它?到目前为止,你可以拨弄一下你的东西:) – 2014-10-30 21:57:01

+0

@BojanPetkovski当左/右位置改变为实际被拖动的元素时,其他位置将以相同的方式被操纵。如果有可能增加延迟,使它像蛇一样,那就太好了。但我不知道该怎么做。 – wordSmith 2014-10-30 21:58:49

+0

@BojanPetkovski好了,用js小提琴更新。 – wordSmith 2014-10-30 22:06:45

回答

2

在这里,你是使用jQuery UI http://jsfiddle.net/7ta68xyt/5/

$(".dismissAllButton").draggable({ 
    axis: 'x', 
    containment: 'parent', 
    start: function (event, ui) { 
     posTopArray = []; 
     posLeftArray = []; 
     if ($(this).hasClass("group")) { 
      $(".group").each(function (i) { 
       thiscsstop = $(this).css('top'); 
       if (thiscsstop == 'auto') thiscsstop = 0;  
       thiscssleft = $(this).css('left'); 
       if (thiscssleft == 'auto') thiscssleft = 0;  
       posTopArray[i] = parseInt(thiscsstop); 
       posLeftArray[i] = parseInt(thiscssleft); 
      }); 
     } 

     begintop = $(this).offset().top; 
     beginleft = $(this).offset().left; 
    }, 
    drag: function (event, ui) { 
     var topdiff = $(this).offset().top - begintop; 
     var leftdiff = $(this).offset().left - beginleft; 

     if ($(this).hasClass("group")) { 
      $(".group").each(function (i) { 
       $(this).css('top', posTopArray[i] + topdiff); 
       $(this).css('left', posLeftArray[i] + leftdiff); 
      }); 
     } 
    } 
}); 
相关问题