I've been trying to use Javascript Drag and Drop API.
var file = document.getElementById('file');
file.addEventListener('dragstart', function(evt){
evt.dataTransfer.setData("DownloadURL",fileDetails);
}, false);
That works and all, but is there any way to use jQuery "on" to catch the event? I've tried
$('#file').on('dragstart', function(evt) {
console.log(evt.dataTransfer); // this returns undefined
evt.dataTransfer.data("DownloadURL",fileDetails); // so this produces error
});
But it doesn't work.
If possible, I don't want to use jQuery draggable plugin, since I'm not really looking to have a cross-browser solution.
Thanks
The dragstart event is fired when the user starts dragging an element or text selection.
The ondragstart event occurs when the user starts to drag an element or text selection. Drag and drop is a very common feature in HTML5. It is when you "grab" an object and drag it to a different location.
The drag event is fired every few hundred milliseconds as an element or text selection is being dragged by the user.
You have to use the property originalEvent
of the jquery event to access native properties of the javascript listener, like this:
evt.originalEvent.dataTransfer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With