当您将文件从桌面拖到浏览器时触发的 Javascript 事件是什么
我正在尝试实现一个类似于 gmail 的文件上传系统。我已经完成了所有 Fileupload / AJAX 问题,并且效果完美。我遇到的唯一问题是用户反馈。
例如..在gmail中,当您将文件拖到浏览器(假设IE9+用户)时,会弹出一个区域,让您将文件放入其中。我认为这是由框架捕获的某种JavaScript事件(比如说 Jquery),它允许我在放置区域制作一些很酷的动画。
我的问题很简单..我应该捕获什么事件来执行此操作?有什么想法吗?我做错了吗?
I'm trying to implement a file upoload system similar to gmail's. I've already done all the Fileupload / AJAX issue and it works perfect. The only problem that I have is User Feedback.
For example.. in gmail, when you drag a file to your browser (assuming IE9+ user), there's an area that pops up, letting you drop the file in. I think it is some kind of JavaScript event that is captured by a framework (let's say Jquery), that allows me to make some cool animations on the drop area.
My question is simple.. What event should I capture to do this? Any ideas? Am I doing it wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
主要事件就是
drop
。您还需要处理
dragenter
和dragleave
否则放置操作只会导致加载放置的文件。您还可以选择观看dragover
。我有一些注册这些处理程序的代码,如下所示:
在这种情况下,
dragenter
和dragleave
处理程序只是为了在拖动东西时更改放置区域的外观进入其中。The main event is just
drop
.You will also need to handle
dragenter
anddragleave
otherwise the drop action will just cause a load of the dropped files. You may optionally also watchdragover
.I have some code that registers these handlers, like so:
In this case the
dragenter
anddragleave
handlers are there just to change the appearance of the drop zone when stuff is being dragged into it.它称为
drop
,您需要的事件对象属性将位于originalEvent 属性中。如果我没记错的话,您还需要在同一元素上取消绑定dragenter和dragleave,以便它触发放置事件。
It's called
drop
, and the properties you need from the event object will be in the originalEvent property.you also need to unbind the dragenter and dragleave on that same element for it to fire the drop event, if I remember correctly.