【问题标题】:jQuery Drag & Drop Simulate PluginjQuery拖放模拟插件
【发布时间】:2015-10-01 16:05:39
【问题描述】:

提前感谢您查看此内容!我无法通过此处找到的扩展插件模拟 jQuery UI 提供的拖放功能:

https://github.com/j-ulrich/jquery-simulate-ext/blob/master/doc/drag-n-drop.md

该文档使用了以下内容,我根据自己的需要对其进行了修改:

$('#draggableDiv').simulate("drag", {dragTarget: otherDiv});

Changed to this:
$('#placeme').simulate("drag", {dragTarget: $("#page1")});

我的警报消息永远不会弹出,因此很明显 drop 函数从未被触发,我不知道为什么。手动将对象拖动到 page1 行为正常。

JSFiddle: http://jsfiddle.net/d2fdvxhz/8/

HTML:

<div class="container">
    <div id="view-port">
        <div id="placeme" class="droppableShape">
            <img src="https://upload.wikimedia.org/wikipedia/en/6/6f/Smiley_Face.png" width="25" height="25" />
        </div>
        <button id="testme">Simulate Drop</button>
        <div class="page" id="page1" style="background-image: url(http://images.huffingtonpost.com/2012-08-15-1CanvasPanelInstall5psd.jpg);"></div>
        <!-- Pages Here -->
    </div>
</div>

JS:

$(document).ready(function(){
     $(".droppableShape").draggable({
            helper:'clone'
     });

    $(".page").droppable({
        accept: ".droppableShape",
        tolerance: 'fit',
        drop: function(event,ui){
            alert("Drop Detected");

            var new_field = $(ui.helper).clone().removeClass('droppableShape');
            var droppable_page = $(this);
            var droppableOffset = $(this).offset();
            new_field.css('top', ui.position.top - droppableOffset.top);
            new_field.css('left', ui.position.left - droppableOffset.left);

            // Set Draggable Options
            new_field.draggable({
                containment: droppable_page,
                stop: function(event, ui) {
                    // Save position after dragging stops
                    $(this).data("x_cord", ui.position.left);
                    $(this).data("y_cord", ui.position.top);
                    $(this).draggable( "disable" );
                }
            });

            // Add to drop area
            $(this).append(new_field);
        }
    });

    $( "#testme" ).click(function() {
        $('#placeme').simulate("drag", {
            dragTarget: $("#page1")
        });
        console.log("Simulate Attempted");
    });
});

【问题讨论】:

    标签: javascript jquery jquery-ui drag-and-drop simulate


    【解决方案1】:

    你应该使用

    $('#placeme').simulate("drag-n-drop", {
    

    据记录 here

    工作fiddle

    如果您只模拟拖动,则永远不会发生下降

    【讨论】:

    • 感谢您的帮助!这在小提琴中奏效,试图将其应用于我的真实项目,因为我无法发布源代码。非常感谢您的时间。
    猜你喜欢
    • 1970-01-01
    • 2010-11-26
    • 1970-01-01
    • 2010-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-16
    相关资源
    最近更新 更多