Pass object through dataTransfer

前端 未结 2 677
你的背包
你的背包 2021-01-31 08:16

I\'m trying to figure out a way to pass a native object through javascript\'s event.dataTransfer for drag and drop. I\'m writing the front end editor portion of a CMS, and want

2条回答
  •  囚心锁ツ
    2021-01-31 08:34

    Maybe what I am about to suggest is wrong (if so I will be happy to hear why ). Why not set a variable in the dragstart listener to reference what you need, for example:

    //global variable
    var obj;
    
    //set the global variable to wahtever you wish in the dragstart:
    $dragme.on("dragstart", function(e) {
        obj = foo;
        //or even obj = document.getElementById("some element's id");
    });
    
    //use this obj in the drop listener.
    $dropzone.on("drop", function(e) {
        obj.doWahtEver();
    });
    

提交回复
热议问题