我在骨干应用程序中使用默认拖放功能我在我的视图中正在监听事件:
"drop img.big-objet": "dragDropEvent",
"dragenter img.objet": "dragEnterLeaveEvent",
"dragleave img.big-objet": "dragEnterLeaveEvent",
"mousedown img.big-objet": "dragStartEvent",
"mouseup img.big-objet": "dragStopEvent",
"dragend img.big-objet": "dragStopEvent",
使用相关方法
dragEnterLeaveEvent: function (event){
object = $(event.target);
object.addClass('hidden');
$('#'+object.attr('data-toggle')).removeClass('hidden');
},
dragStartEvent: function (event) {
object = $(event.target);
object.addClass('objet-drag').removeClass('objet-hover');
},
dragStopEvent: function (event) {
object = $(event.target);
object.addClass('objet-hover').removeClass('objet-drag');
},
objectHover: function(event){
object = $(event.target);
object.addClass('hidden');
$('#'+object.attr('data-toggle')).removeClass('hidden');
},
dragDropEvent: function(event){
alert('banana');
}
以及相关的html
<img class="objet" id="small-objet01-level01" data-toggle="big-objet01-level01" src="img/content/small-objet01-level01.png" alt="" />
<img class="objet" id="small-objet02-level01" data-toggle="big-objet02-level01" src="img/content/small-objet02-level01.png" alt="" />
<img class="objet" id="small-objet03-level01" data-toggle="big-objet03-level01" src="img/content/small-objet03-level01.png" alt="" />
<img class="big-objet objet-hover hidden" id="big-objet01-level01" draggable="true" data-toggle="small-objet01-level01" src="img/content/big-objet01-level01.png" alt="" />
<img class="big-objet objet-hover hidden" id="big-objet02-level01" draggable="true" data-toggle="small-objet02-level01" src="img/content/big-objet02-level01.png" alt="" />
<img class="big-objet objet-hover hidden" id="big-objet03-level01" draggable="true" data-toggle="small-objet03-level01" src="img/content/big-objet03-level01.png" alt="" />
我的所有活动都正常,但不是drop事件。所以我的问题是它是如何运作的?
答案 0 :(得分:2)
使用JQuery UI库而不是HTML5拖放进行修复。
我把它放在我的渲染方法中:
$('#overlay-objet img').droppable({
tolerance: 'pointer',
drop: _.bind(function(event, ui) {
object = $(event.target);
if (object.attr("data-val") != undefined){
objectDrag = object.attr('data-val').toString();
objectDrop = $(ui.draggable).attr('data-val').toString();
object.addClass('hidden');
$('#'+object.attr('data-toggle')).removeClass('hidden');
this.dragDropEvent(objectDrag + objectDrop);
}
}, this),
over: _.bind(function(event,ui){
object = $(event.target);
object.addClass('hidden');
$('#'+object.attr('data-toggle')).removeClass('hidden');
}, this),
out: _.bind(function(event,ui){
object = $(event.target);
object.removeClass('hidden');
$('#'+object.attr('data-toggle')).addClass('hidden');
}, this) // Edit mercredi soir ajouter ,this dans chaque callback
});
$('img.big-objet').draggable({
helper: "clone"
});
答案 1 :(得分:0)
快速查看它,看起来你在'objectHover'之后错过了逗号。