使用实时事件的 jQuery 拖放 [英] jQuery Drag And Drop Using Live Events

查看:25
本文介绍了使用实时事件的 jQuery 拖放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,其中包含一个经常更改的长列表,我需要该列表中的项目是可拖动的.

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

我一直在使用 jQuery UI 可拖动插件,但是添加到 400 多个列表项很慢,并且每次添加新列表项时都必须重新添加.

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.

有谁知道一个类似于使用 jQuery 1.3 的 .live() 事件的 jQuery UI 可拖动插件的插件?这将解决这两个问题.

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.

推荐答案

Wojtek 的解决方案非常适合我.我最终对它进行了一些更改以使其扩展 jQuery ...

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});

...只需使用:

$(selector).liveDraggable({opts})

这篇关于使用实时事件的 jQuery 拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆