Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Drag And Drop Using Live Events

I have an application with a long list that changes frequently, and I need the items of that list to be draggable.

I've been using the jQuery UI draggable plugin, but it is slow to add to 400+ list items, and has to be re-added every time new list items are added.

Does anyone know of a plugin similar to the jQuery UI draggable plugin that uses jQuery 1.3's .live() events? This would solve both problems.

like image 410
devongovett Avatar asked Nov 26 '09 19:11

devongovett


2 Answers

Wojtek's solution worked perfectly for me. I wound up changing it a tad bit to make it extend jQuery...

(function ($) {    $.fn.liveDraggable = function (opts) {       this.live("mouseover", function() {          if (!$(this).data("init")) {             $(this).data("init", true).draggable(opts);          }       });       return this;    }; }(jQuery)); 

Now instead of calling it like:

$(selector).draggable({opts}); 

...just use:

$(selector).liveDraggable({opts}) 
like image 108
stldoug Avatar answered Oct 05 '22 14:10

stldoug


This is a sample of code that perfectly worked for me

$('.gadgets-column').live('mouseover',function(){     $(this).draggable(); }); 
like image 23
Jasim Muhammed Avatar answered Oct 05 '22 12:10

Jasim Muhammed