【问题标题】:jQuery - Draggable resize to fit placeholderjQuery - 可拖动调整大小以适合占位符
【发布时间】:2015-06-18 17:41:42
【问题描述】:

我有不同的可拖动元素。它们可以拖动到占位符中(100px x 100px),但可拖动元素的宽度为 100%(主体宽度)。

现在,当我开始拖动时,我会触发调整大小功能:

// Dragging itself

function dragging () {

    $("#draggable li.to-drag").draggable({

        connectToSortable: ".items",
        helper: "clone",
        revert: false,
        opacity: 0.5,
        cursorAt: { top: 50, left: 50},

        drag: resize,

        start: function (event, ui) {

            ui.draggable.height(ui.placeholder.outerHeight());

        }

    });

}

// Resize function triggered when I start dragging

function resize (event, ui) {

    ui.helper.css({ height: "100px", width: "100px" });

}

由于可拖动元素的宽度大于占位符,我无法让占位符接受可拖放元素。

听起来很复杂,但这里有一个jsfiddle

【问题讨论】:

    标签: javascript jquery jquery-ui


    【解决方案1】:

    你小提琴第70行有错误:

    tolerance: pointer,
    

    指针未定义

    替换为

    tolerance: "pointer",
    

    一切都应该正常工作

    jsfiddle

    【讨论】:

      【解决方案2】:

      问题不在于宽度为 100%。您已更改 cursorAt 以使其位于可拖动项目的中心。但它仍会寻找原始光标位置来放置元素

      【讨论】:

        猜你喜欢
        • 2013-06-05
        • 1970-01-01
        • 1970-01-01
        • 2011-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多