Is it possible to link two jquery.ui draggables together?

前端 未结 5 1737
生来不讨喜
生来不讨喜 2020-12-18 05:07

I have two jquery.ui draggables. I am constraining their movement to the y-axis. If one is dragged to a certain y-position, I want the other to automatically move to the s

5条回答
  •  时光说笑
    2020-12-18 05:50

    Here is a simplified version of the code mentioned in the marked answer(for dummies like me):

    • In HTML

      ...
      ...
    • In Script tag

      $(document).ready(function(){ 
          //to get the group 
          var getGroup = function() {
              return $(".group");
          }; // add drag functionality
      
          $(".group").draggable({
              revertDuration: 10,
              // grouped items animate separately, so leave this number low
              containment: "window",
              scroll: false,
              stop: function(e, ui) {
                  getGroup(ui).css({
                      'top': ui.helper.css('top'),
                  });
              },
              drag: function(e, ui) {
                  getGroup(ui).css({
                      'top': ui.helper.css('top'),
                      'left': ui.helper.css('left')
                  });
              }
          });     
      });
      

提交回复
热议问题