我想在Velocity的Progress Function中访问我的插件的Public方法。但我无法让它发挥作用
此方法使用公共函数创建元素
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;
};
};
在此点我需要在Velocity中访问我的插件的Seek功能,但是如何让它工作?
$('.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) {
// ?
}
});
}
});
答案 0 :(得分:0)
知道了。如果我以这种方式设置公共方法,它现在适用于我。
$.fn.feedseed.seek = function (multiplier) {
// do something
};