开发者

How do I customize the helper using draggable in jQuery-UI

I want to make a custom element with text taken from the element "being drag开发者_开发技巧ged" using a helper function. My problem is that ui is undefined, so I don't know how to get a hold of the source of the drag.

$('.draggable').draggable({
    helper: function(event, ui) {
        var foo = $('<span style="white-space:nowrap;">DRAG TEST</span>'); 
        return foo;
    }
});


The helper function you're applying is invoked the following way:

 $(o.helper.apply(this.element[0], [event]))

That means that this refers to the .draggable you want inside that function, for example:

$('.draggable').draggable({
  helper: function(event) {
    return $('<span style="white-space:nowrap;"/>')
            .text($(this).text() + " helper");
  }
});

You can test it out here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜