简体   繁体   English

HTML 5 - Drag n Drop - 如果放置目标被完全占用,则不会触发 ondragover 事件

[英]HTML 5 - Drag n Drop - ondragover event not triggered if the drop target is fully occupied

I have a container with left pane and right pane.我有一个带有左窗格和右窗格的容器。 You can drag from left pane, and drop on right pane.您可以从左窗格拖动,然后放在右窗格中。 For some reason, the html 5 ondragover event is not triggered if the drop target is already completely occupied.出于某种原因,如果放置目标已完全被占用,则不会触发 html 5 ondragover 事件。 My drop target is a div, and I would be dynamically creating iframes in it when ondrop event occurs.我的放置目标是一个 div,当 ondrop 事件发生时,我会在其中动态创建 iframe。 I am able to create the 1st iframe when I drag something for the first time from left and drop it to left.当我第一次从左侧拖动某些东西并将其放到左侧时,我能够创建第一个 iframe。 But now for the 2nd time if I drag something from the left and try to drop it to right, the ondragover is not getting triggered(I put the breakpoint, its not getting hit), because the drop target is already full with my 1st iframe.但是现在第二次,如果我从左边拖动一些东西并尝试将它放到右边,ondragover 不会被触发(我放置断点,它没有被击中),因为放置目标已经满了我的第一个 iframe . In the ondragover listener I would like to reduce the height of existing iframe to half, so as to make room for creation of new iframe.在 ondragover 侦听器中,我想将现有 iframe 的高度降低一半,以便为创建新的 iframe 腾出空间。 But unfortunately the ondragover is just not getting triggered.但不幸的是,ondragover 并没有被触发。 Is there any way I can modify the behaviour of ondragover, so that it gets triggered even if the drop target is completely occupied?有什么方法可以修改 ondragover 的行为,以便即使放置目标完全被占用它也会被触发? Any help would be greatly appreciated.任何帮助将不胜感激。 So, here is the code..所以,这是代码..

function onDragOver(ev) {
 ev.preventDefault();
 if(iframes_count > 4)
 {
   return;
 }
 if (iframes_count == 2)
 {
    if ((getDivLeftCoordinate() < ev.pageX < getDroppableWidth()) && (getDivTopCoordinate() < ev.pageY < getDroppableHeight()/2))
    {
        var existingFrames = document.getElementsByTagName("iframe");
        for (var i = 0; i < existingFrames.length; i++)
        {
          $(this).attr("height" , 500);
        }
    }
 }
 $("#right_pane").css("background-color", "grey");
}

function onDrop(ev) {
 ev.preventDefault();

var data_id = ev.dataTransfer.getData("Text");
var data_id_selector= "#" + data_id;
var content_id = data_id + "content";
var content_id_selector = "#" + content_id;
var url = $(data_id_selector).data("url");
var iframe_width = 100 + "%";
var iframe_height = 100 + "%";


$(data_id_selector).remove();
$("<iframe />", {
class: "myFrame",
id : content_id,

}).appendTo('#right_pane');



$(content_id_selector).attr("height", iframe_height);
$(content_id_selector).attr("width", iframe_width);
$(content_id_selector).attr("src", url);
$(content_id_selector).attr("background-color", "white");
$("#right_pane").css("background-color", "white");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM