拖动div时如何防止代码运行

问题描述

当在muuri.js或jQuery UI中拖动div时,div将获得“拖动”类。 如何停止事件侦听器运行createHTML();拖动时放开div后是否起作用?我希望单击仅在快速单击后运行功能,而在按住并拖动时不运行。

var loadContentButton = document.getElementById("load-content-button-<?php echo get_the_ID(); ?>");
var loadContentContainer = document.getElementById("content-pop-up");
var loadContentContainerWrap = document.getElementById("pop-up");

if (loadContentButton) {
  loadContentButton.addEventListener("click",function() {
  var ourRequest = new XMLHttpRequest();
  ourRequest.open('GET','http://example.com/wp-json/wp/v2/posts/<?php echo get_the_ID(); ?>');
  ourRequest.onload = function() {

  if (ourRequest.status >= 200 && ourRequest.status < 400) {
     var data = JSON.parse(ourRequest.responseText);
     console.log(data);
     createHTML(data);
     loadContentContainerWrap.classList.add("active-pop-up-main");

  } else {
   console.log("We connected to the server,but it returned an error.");
  }
};

ourRequest.onerror = function() {
console.log("Connection error");
};

ourRequest.send();
  });
}

function createHTML(postsData) {
var ourHTMLString = '';
  ourHTMLString += '<h2>' + postsData.title.rendered + '</h2>';
  ourHTMLString += postsData.content.rendered;
  loadContentContainer.innerHTML = ourHTMLString;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...