2011-04-01 67 views

回答

4

鼠標小部件是一種內部插件,似乎大部分(或僅)用於低級別的拖放處理。

我只是寫了一篇博客文章用它來推出自己的拖放和拖放(而不是使用可拖動):http://www.solitr.com/blog/2012/05/roll-your-own-drag-and-drop-handling-with-jquery-ui/

它的要點是,你可以繼承它,像這樣:

$.widget('ui.custommouse', $.ui.mouse, { 
    options: { 
    mouseStart: function(e) {}, 
    mouseDrag: function(e) {}, 
    mouseStop: function(e) {}, 
    mouseCapture: function(e) { return true; } 
    }, 
    // Forward events to custom handlers 
    _mouseStart: function(e) { return this.options.mouseStart(e); }, 
    _mouseDrag: function(e) { return this.options.mouseDrag(e); }, 
    _mouseStop: function(e) { return this.options.mouseStop(e); }, 
    _mouseCapture: function(e) { return this.options.mouseCapture(e); } 
    // Bookkeeping, inspired by Draggable 
    widgetEventPrefix: 'custommouse', 
    _init: function() { 
    return this._mouseInit(); 
    }, 
    _create: function() { 
    return this.element.addClass('ui-custommouse'); 
    }, 
    _destroy: function() { 
    this._mouseDestroy(); 
    return this.element.removeClass('ui-custommouse'); 
    }, 
}); 

然後實例剛剛定義的custommouse插件,並通過自己的 事件處理程序的選項:

$('#containerElement').custommouse({ 
    mouseStart: function(e) { ... }, 
    mouseDrag: function(e) { ... }, 
    mouseStop: function(e) { ... } 
}); 
1

新的鼠標插件文件使得jQuery UI的平均 小14%的鼠標插件是不是新的,但這種釋放它移動到自己的文件,jquery.ui.mouse.js,它在裏面前jQuery UI Core。這意味着不依賴於鼠標插件但之前包含jQuery UI Core的jQuery UI插件包含較少的未使用代碼,平均整體文件大小提高了14%。這只是一個平均值。一些改進將高達36%。

jQuery blog 2010年3月

在你的jQuery庫(就像this from google),你可以找到它作爲* jQuery UI的鼠標在jQuery UI Mouse in the JQs website 1.8.11和更多信息。

+0

是有任何網站了解有關鼠標小部件的使用情況。 :(??? – Santhanam 2011-04-01 13:21:24

+2

它沒有任何有效的信息.... :( – Santhanam 2011-04-01 13:23:12

相關問題