我想在速度的进度函数中访问插件的公共方法。但是我无法正常工作
此方法使用公共功能创建元素
var animateFeed = function (ms) {
var i = 0;
var animationInterval = setInterval(function () {
if (_tempelements.length > 0) {
var shiftedElement = _tempelements.shift();
shiftedElement.feedseed({
stage: '.socialfeeds',
stageElm: '.feed-post',
id: i++,
y: helper.randInt(0, 150),
speed: helper.randInt(20, 120),
scale: helper.randFloat(0.4, 1.01)
});
socialfeedObject.push(shiftedElement);
}
}, ms);
};
此插件还返回一些公共方法
$.fn.feedseed = function (options) {
// default settings
var settings = $.extend({
element: this,
stage: '',
stageElm: '',
id: 0,
x: 0,
y: 0,
width: 0,
startX: 0,
scale: 1.0,
speed: 100
}, options);
// some more code here...
// Public Function
this.play = function () {
if (!OBJ.isRunning) {
OBJ._then = Date.now();
frame();
OBJ.isRunning = true;
}
return this;
};
// Public Function
this.pause = function () {
cancelAnimationFrame(OBJ.rafid);
OBJ.isRunning = false;
return this;
};
this.seek = function (multiplier) {
settings.speed = settings.speed * multiplier;
return this;
};
};
在这一点
$('.speedup').on('click tap', function () {
for (var i = 0; i < socialfeedObject.length; i++) {
socialfeedObject[i].velocity({
tween: [1, 200]
}, {
duration: 600,
easing: 'easeOutQuad',
progress: function(elements, complete, remaining, start, tweenValue) {
// ?
}
});
}
});
得到了它。如果我以这种方式设置公共方法,它现在对我有效。
$.fn.feedseed.seek = function (multiplier) {
// do something
};