我正在開發一個帶有jQuery和jQuery UI拖放功能的單個工具欄插件。這個想法如下:我有一個列表(ul)和項目(li),其中每個代表像文本,幾何圖形等工具。當我拖動一個工具,然後將其放在主角上時,必須創建一個「小工具」。問題出在工具掉到容器上後,它不再可以通過拖放操作。拖放功能只需一次。Jquery Ui拖放問題
希望你能幫助我。對不起我的英語不好。
這裏是代碼
插件
(function($){
//Attach this new method to jQuery
$.fn.extend({
//This is where you write your plugin's name
spkToolbar: function(options) {
//Set the default values, use comma to separate the settings, example:
var defaults = {
isDraggable:false
,droppableDiv:undefined
};
var options = $.extend(defaults, options);
//Iterate over the current set of matched elements
return this.each(function() {
var o = options;
$(this).addClass('toolbar');
if(o.isDraggable)
$('.toolbar').draggable();
$(this).addClass('spkToolbar');
var obj = $(this);
//Get all LI in the UL
var items = $("ul li", obj);
items.draggable({ appendTo: "body",helper: 'clone' });
if(o.droppableDiv!=undefined){
$(o.droppableDiv).droppable({
drop: function(event, ui) {
// some extra code for proper widget creation
}
});
}
});
}
});
})(jQuery);
的HTML
<div id="toolbar">
<ul>
<li id="save" title="Guardar cambios"><img src="<c:url value="images/toolbar/save.png" />" /></li>
</ul>
</div>
用法:
jQuery('#toolbar').spkToolbar({droppableDiv:'#new-dropcontainer'});
我幾乎忘了,使用jQuery 1.5和jQuery UI 1.8.1
在此先感謝
嗨!是的,我在這裏做了:var items = $(「ul li」,obj); items.draggable({appendTo:「body」,helper:'clone'}); – KalEl98 2011-03-18 02:29:16
是的,對不起,我在工具欄上看到了'draggable()',而不是另一個LOL ......無論如何,請查看購物車演示,瞭解他們如何「放棄」該項目:http://jqueryui.com/demos/ droppable /#購物車 – Mottie 2011-03-18 02:34:21