我为我的插件使用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