Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery:获取HTML5放置的位置_Javascript_Jquery_Html - Fatal编程技术网

Javascript jQuery:获取HTML5放置的位置

Javascript jQuery:获取HTML5放置的位置,javascript,jquery,html,Javascript,Jquery,Html,我正在制作一个带有tabpane的web应用程序。要在选项卡窗格周围移动选项卡并将其移动到其他窗口中,我使用的是原生HTML拖放 要在选项卡窗格中移动选项卡,用户需要将一个选项卡拖到另一个选项卡上,然后根据在选项卡上拖动的位置将其放置在左侧或右侧。我不确定如何找到标签在另一个标签上的位置 $(document).on('dragstart', '.tabpane li', function(e) { ... }); $(document).on('dragover', '.tabpane

我正在制作一个带有tabpane的web应用程序。要在选项卡窗格周围移动选项卡并将其移动到其他窗口中,我使用的是原生HTML拖放

要在选项卡窗格中移动选项卡,用户需要将一个选项卡拖到另一个选项卡上,然后根据在选项卡上拖动的位置将其放置在左侧或右侧。我不确定如何找到标签在另一个标签上的位置

$(document).on('dragstart', '.tabpane li', function(e) {
  ...
});

$(document).on('dragover', '.tabpane li', function(e) {
  e.preventDefault();
});

$(document).on('drop', '.tabpane li', function(e) {
  var droppedOnTabAt = ? ? ? ; // How do I find this?

  if (droppedOnTabAt.x > $(this).width() / 2) {
    // move tab to the right of the dropped onto tab
  } else {
    // move tab to the left of the dropped onto tab
  }
});

通过阅读更多的内容来解决我的问题


检查事件对象
$(document).on('drop', '.tabpane li', function(e) {
  var droppedOnTabAt = e.originalEvent.clientX; // Gets the x position of the drop relative to the window
  var tabMiddlePos = $(this).offset().left + $(this).width() / 2; // Gets the center of width of the tab dropped on relative to the window

  if (droppedOnTabAt > tabMiddlePos ) {
    // move tab to the right of the dropped onto tab
  } else {
    // move tab to the left of the dropped onto tab
  }
});