我正在研究一些效果和东西来处理类/实现/扩展。这里的例子是用于基类(MooSlidesFx、MooSlidesFx.Elements),通过我正在处理的项目创建许多效果,以及两个实际上做某事的子类(MooSlidesFx.Fade、MooSlidesEffects.Elements.Fade)。
http://paste.mootools.net/m6afc7746
第一个类 MooSlidesFx 为其他人设置了东西,旨在实现。
第二个类,MooSlidesFx.Elements,扩展了 MooSlidesFx 以同样被实现,但不仅仅是动画传入的元素,它会按顺序动画它的孩子(现在不是在寻找课程链,但它是我列表中的下一个!) ,因此重新定义了一些方法。
第三类 MooSlidesFx.Fade 效果很好。它实现了 MooSlidesFx,定义了两个小方法,然后我们就开始比赛了。
然后是问题。看来 我可以同时实现 MooSlidesFx.Elements 和 MooSlidesFx.Fade 和 POW !我有一个新效果,它不会淡入元素,而是淡入它的孩子交错。
不是这样,谢谢你的帮助!
这是一大堆代码:
var MooSlidesFx = new Class({
Implements: Options,
options: {
delay: 0,
duration: 500,
how: 'in',
transition: 'sine:in:out'
},
initialize: function(el,options){
this.setOptions(options);
this.el=$(el);
this.animation = this.setAnimation(el);
},
animate: function(){
this.animation.set($clear);
var calculations = this.calculate(this.el);
this.animation.set(calculations[0]);
var delayed = function(){
this.animation.start(calculations[1])
}.bind(this).delay(this.options.delay);
},
getDuration: function(){
return this.options.delay+this.options.duration
}
});
MooSlidesFx.Elements = new Class({
Extends: MooSlidesFx,
options: {
selector: false,
elementDelay: 200,
order: 'normal'
},
animations: [],
initialize: function(el,options){
console.log('Elements initialize');
this.parent(options);
this.elements=this.el.getElements(this.options.selector);
this.elements.each(function(el,index){
this.animations.include(this.setAnimation(el,index));
}.bind(this));
},
animate: function(){
var eachDelay = this.options.elementDelay;
var calculations=[];
this.animations.each(function(animation,index){
animation.set($clear);
calculations.include(this.calculate(index));
animation.set(calculations[0]);
}.bind(this));
var delayed = function(){
this.elements.each(function(el,i){
var go = function(){
console.log('going '+i)
this.animations[i].start(calculations[i][1]);
}.bind(this).delay(d);
eachDelay = eachDelay + this.options.elementDelay;
}.bind(this));
}.bind(this).delay(this.options.delay);
},
getDuration: function(){
return this.options.delay+this.options.duration+((this.elements.length-1)*this.options.elementDelay);
}
});
MooSlidesFx.Fade = new Class({
Implements: MooSlidesFx,
setAnimation: function(el){
var animation = new Fx.Tween(el,{
property: 'opacity',
duration: this.options.duration,
transition: this.options.transition,
});
return animation;
},
calculate: function(el){
return (this.options.how=='in') ? [0,1] : [1,0];
}
});
MooSlidesFx.Elements.Fade = new Class({
Implements: [MooSlidesFx.Fade,MooSlidesFx.Elements]
// TypeError: Result of expression 'this.caller._owner.parent' [undefined] is not an object.
// mootools-core.js (line 1173)
});
MooSlidesFx.Elements.Fade = new Class({
Implements: MooSlidesFx.Fade,
Extends: MooSlidesFx.Elements
// TypeError: Result of expression 'this.setAnimation' [undefined] is not a function.
// MooSlides.Fx.js (line 15)
});
MooSlidesFx.Elements.Fade = new Class({
Implements: [MooSlides.Fx.Fade, MooSlidesFx.Elements]
// line 49 is never logged, so Elements isn't ever initialized, acts just like MooSlidesFx.Fade
});
/***** usage *****/
var fx = new MooSlidesFx.Elements.Fade('test',{ selector: 'li'}).animate();
/*
HTML
<ul id="test">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
*/