我正试图将这个盒子从男人拖到车顶,目标div称为'droppable'。这似乎在从Dreamweaver预览时有效,但在jsfiddle中预览时无效:
http://jsfiddle.net/dantest2014/9JTSQ/7/
$(function () {
var dfd1 = $.Deferred();
var dfd2 = $.Deferred();
$("#lft_box_layer").draggable({
revert: "invalid",
cursor: "move"
});
$("#rgt_box_layer").draggable({
revert: "invalid",
cursor: "move"
});
$("#btm_box_layer").draggable({
revert: "invalid",
cursor: "move"
});
$("#droppable").droppable({
accept: "#lft_box_layer, #rgt_box_layer, #btm_box_layer",
// tolerance can be set to 'fit', 'intersect', 'pointer', or 'touch'
tolerance: 'intersect',
// Add .hoverClass whenever #draggable is being hovered over #droppable
over: function (event, ui) {
$('.ui-draggable-dragging').addClass('hover');
},
// Remove .hoverClass whenever #draggable is no longer hovered over #droppable
out: function (event, ui) {
$('.ui-draggable-dragging').removeClass('hover');
},
// Add .dropClass whenever #draggable is dropped on #droppable
drop: function (event, ui) {
$('.ui-draggable-dragging').removeClass('hover').addClass('drop');
$('.ui-draggable-dragging').draggable('option', 'disabled', true);
$("#car").attr('src', "images/removals-car-break.jpg");
}
});
});
有人可以帮我这个吗?
将三个方框拖到汽车顶部后,我想触发更改汽车图像并更改文字。
对这个问题的任何部分的任何帮助都会很棒。 谢谢! 丹
答案 0 :(得分:0)
为了在JSFiddle上预览它,首先需要在项目上实现jQueryUI(而不仅仅是jQuery)。
以下是与jQueryUI绑定到项目中的相同示例(并且稍微清理了代码以免浪费代码调用所有元素的draggable):http://jsfiddle.net/9JTSQ/11/
$(".toDrag").draggable({
revert: "invalid",
cursor: "move"
});
$("#droppable").droppable({
accept: ".toDrag",
.....................
});
我刚从“外部资源”中的CDN绑定了jQueryUI