Question

Is it possible to set the helper in jquery draggable only if (let's say) the control key is pressed when you start dragging? I tried this:

start: function( event, ui ) {
    ui.helper = !cntrlIsPressed ? "original" : $("<div></div>").text($(this).text()).css({    "background": $(this).css("background"), "padding": $(this).css("padding") }).attr({"data-predmetId": $(this).attr("data-predmetId"), "data-predmetNaziv": $(this).attr("data-predmetNaziv")}).addClass("helper");
}

Thank you!

Was it helpful?

Solution

Yes it's possible, helper option accept a function:

A function that will return a DOMElement to use while dragging.

here you can check if the CTRL is pressed and act accordingly, keep in mind to return a jQuery/DOM element.

Code:

$(function () {
    $("#draggable").draggable({
        helper: function (evt) {
           return !evt.ctrlKey ? $(this) : $("<div>Demooooooo</div>");
        }
    });
});

Demo: http://jsfiddle.net/mt5Mr/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top