简体   繁体   English

拖放jQuery不起作用

[英]drag and drop jquery not working

I'm trying to drag the boxes from the man to the top of the car, target div called 'droppable'. 我正在尝试将盒子从人拖到汽车的顶部,目标div称为“可放下”。 This seems to work when previewing from Dreamweaver but not when previewing in jsfiddle: 从Dreamweaver进行预览时似乎可行,但在jsfiddle中进行预览时则无效:

http://jsfiddle.net/dantest2014/9JTSQ/7/ 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");


    }

});

}); });

Can someone help me with this? 有人可以帮我弄这个吗?

After the three boxes have been dragged to the top of the car I would like to trigger a change of car image and also change the text. 将三个方框拖到汽车顶部后,我想触发汽车图像的更改并更改文本。

Any help with any part of this question would be great. 对这个问题的任何部分的任何帮助将是巨大的。 Thanks! 谢谢! Dan

In order to preview it on JSFiddle you first need to implement jQueryUI (not just jQuery) on the project. 为了在JSFiddle上预览它,您首先需要在项目上实现jQueryUI(不仅仅是jQuery)。

Here is the same example with jQueryUI bound into your project (and cleaned the code a little to not waste code calling the draggable for all of the elements): http://jsfiddle.net/9JTSQ/11/ 这是将jQueryUI绑定到您的项目中的同一示例(并清理了一些代码以免浪费代码调用所有元素的可拖动对象): http : //jsfiddle.net/9JTSQ/11/

    $(".toDrag").draggable({
        revert: "invalid",
        cursor: "move"
    });

    $("#droppable").droppable({    
        accept: ".toDrag",
        .....................    
    });

I just bound jQueryUI from its CDN in "external resources" 我只是将jQueryUI从其CDN绑定到“外部资源”中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM