Sunday 15 May 2011

html5 - HTML 5 drag and drop How to figure out whether an element accepts a drop -


Drag and drop the HTML, trying to work out to allow a drop on an element,

According to:

You can not read the datatransfer datastore on the drawer. Since the drawer is an event that you are supposed to cancel, to indicate that you accept a drop - and during the drag-overs you can not tell what is being dragged, How does this work? Am I clarifying something here?

It seems that if any chance of being dragged can be left on your element, then you can cancel the drawer / drenter, but you can only know what was going on in the drop Pulled on

So - we've got a way to do this.

You can to read the dataTransfer.types property, which gives a list of types that are added through the set data. So if you use a custom string as one of those types, then you can see that to verify the existence of the drag data you have added to it.

For example,

  event.dataTransfer.setData ("SpecialAmbedAdvancedAdsource", Data);   

Then in Dragen you can see that this type exists:

  function ondragover (ev) {if (ev.dataTransfer.types & amp; Ev .datatransfer.types.indexOf ("special nameofdragrasource") & gt; -1) {// cancel event}}    

No comments:

Post a Comment