ac3*_*360 1 javascript jquery backbone.js
我有一个带有两个主干视图的仪表板.一个视图包含各种拖放区域,另一个包含项目draggable="true".但是,这些掉落区域并没有对drop事件发射,但它们正在射击dragenter和dragleave.为什么掉落事件没有解雇?
注意:正在呈现的模板包含.item-drop-zonediv元素
包含丢弃区域的视图:
Shopperater.Views.ModuleMedleyView = Backbone.View.extend({
tagName: "div",
className: "row",
template: JST['modules/medley'],
initialize: function() {
_.bindAll(this);
},
events: {
'dragenter .item-drop-zone' : 'highlightDropZone',
'dragleave .item-drop-zone' : 'unhighlightDropZone',
'drop .item-drop-zone' : 'dropTest'
},
dropTest: function(e) {
console.log("dropped!")
},
highlightDropZone: function(e) {
e.preventDefault();
$(e.currentTarget).addClass('item-drop-zone-highlight')
},
unhighlightDropZone: function(e) {
$(e.currentTarget).removeClass('item-drop-zone-highlight')
},
render: function () {
this.$el.html(this.template({ }));
return this;
}
});
Run Code Online (Sandbox Code Playgroud)
您必须告诉浏览器该元素是放置目标:
events: {
'dragenter .item-drop-zone' : 'highlightDropZone',
'dragleave .item-drop-zone' : 'unhighlightDropZone',
'drop .item-drop-zone' : 'dropTest',
'dragover .item-drop-zone': function(ev) {
ev.preventDefault();
}
}
Run Code Online (Sandbox Code Playgroud)
有关放置目标的详细信息,请参阅https://developer.mozilla.org/en-US/docs/DragDrop/Drag_Operations#droptargets.你需要dragenter和dragover事件.既然你已经在做了dragenter,你可以添加dragover.
从链接
preventDefault在adragenter和dragoverevent 期间调用该方法将指示drop在该位置允许a .
| 归档时间: |
|
| 查看次数: |
1936 次 |
| 最近记录: |