如何解决拖动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 举报,一经查实,本站将立刻删除。