我爲我的插件使用jquery boilerplate模板。我需要從這個插件提供一些回調。這個回調需要一些帶有偏移座標的變量。jQuery插件回調 - jQuery Boilerplate
var coordinates = {
x: x2, y: y2
};
我試圖委派這個回調是這樣的:
;(function ($, window, document) {
/* 'use strict'; */
// default options
var name = "plugin",
defaults = {};
// constructor
function plugin (options, callback) {
this.settings = $.extend({}, defaults, options);
this.init();
this.callback = callback;
}
plugin.prototype = {
init: function() {
var offset = $(this).offset(),
x2 = (e.pageX - offset.left),
y2 = (e.pageY - offset.top);
$(document).on('mouseup', function() {
var coordinates = {
x: x2, y: y2
};
this.callback(coordinates);
});
}
};
// initialize
$.fn[name] = function (options, callback) {
return this.each(function() {
if (!$.data(this, "plugin_" + name)) {
$.data(this, "plugin_" + name, new plugin(options, callback));
}
});
};
})(jQuery, window, document);
我有一個arror該回調是不是這個對象的方法。任何人都可以幫忙嗎?
請提供有關如何撥打回撥的詳細信息。 – Kiruse
這就是我所有的,我不知道如何做到這一點... – Lukas
我不相信你。你是說你用那個itzy bitzy代碼代替'function Plugin(){...}?如果是這樣,你的回調電話*完全*不合適。你在網上的某個地方有鏈接到你的代碼嗎?像Gist一樣? – Kiruse