我正在尝试将文件放入我网站上的文件夹中。它完美适用于镀铬,但事件不会在野生动物园中发射。我似乎可以通过文件获取drop事件。虽然我可以拖放网站中的元素。
$(document).on('dragstart', '.mtdrg', dragStart);
$(document).on('dragenter', '.mtdrp', dragEnter);
$(document).on('dragover', '.mtdrp', dragOver);
$(document).on('dragleave', '.mtdrp', dragLeave);
$(document).on('drop', '.mtdrp', drop);
$(document).on('dragend', '.mtdrp', dragEnd);
dragStart = function (e) {
var element = $(this),
instanceid = element.data('instanceid'),
entitytype = element.data('entitytype'),
vmtype = element.data('vmtype');
if (!isAnyMoveAllowed(entitytype, vmtype)) {
e.preventDefault();
return false;
}
$(document.documentElement).addClass('dragActive');
origBackgroundColor = $(this).css('backgroundColor');
this.style.opacity = 0.8;
this.style.backgroundColor = 'rgba(0, 161, 255,.75)';
e.originalEvent.dataTransfer.effectAllowed = 'move';
setDragData(instanceid, entitytype, vmtype);
};
dragOver = function (e) {
if (e.preventDefault) {
e.preventDefault(); // Necessary. Allows us to drop.
}
$(document.documentElement).addClass('dragActive');
var targetEntityType = $(this).data('entitytype');
var targetViewModelType = $(this).data('vmtype');
if (isMoveAllowed(targetEntityType, targetViewModelType, e)) {
e.originalEvent.dataTransfer.dropEffect = 'move';
} else {
e.originalEvent.dataTransfer.dropEffect = 'none';
}
return false;
};
dragEnter = function () {
$(this).addClass('mtdrpHover');
};
dragLeave = function () {
$(this).removeClass('mtdrpHover');
};
drop = function (e) {
if (e.stopPropagation) {
e.stopPropagation(); // stops the browser from redirecting.
}
if (e.originalEvent.dataTransfer.types != null) {
if (e.originalEvent.dataTransfer.files.length > 0) {
$(document.documentElement).removeClass('dragActive');
$(this).removeClass('mtdrpHover');
performFileDrop($(this).data('instanceid'), e);
return false;
}
}
var x = e.originalEvent.offsetX;
var y = e.originalEvent.offsetY;
performDrop($(this).data('instanceid'), $(this).data('dropcontroller'), $(this).data('dropaction'), x, y);
return false;
};
答案 0 :(得分:0)
我需要停止传播并阻止多个事件中的默认值才能正常工作。
dragOver = function (e) {
if (e.preventDefault) {
e.preventDefault(); // Necessary. Allows us to drop.
e.stopPropagation();
}
};
dragEnter = function (e) {
e.preventDefault();
e.stopPropagation();
$(this).addClass('mtdrpHover');
};
drop = function (e) {
if (e.stopPropagation) {
e.preventDefault();
e.stopPropagation(); // stops the browser from redirecting.
}
};