0
我一直在学习Mootools,但我在解决自定义事件时遇到问题。我确信它一定是简单的,但我无法看到它在我的生活中。为什么自定义事件不适合我? (Mootools)
我写了一个简单的类来使用Fx.Tween来推动一些列表项。它完美的工作,除了自定义事件没有被触发,无论我尝试什么。
<script type="text/javascript">
var Pusher = new Class({
Implements: [Events,Options],
options: {
elements: []
},
initialize: function(options){
this.setOptions(options);
this.attachListeners(this.options.elements);
},
attachListeners: function(elements){
$$(elements).each(function(el){
$(el).addEvent('mouseover', this.pushIn.bind(el))
.addEvent('mouseout', this.pushOut.bind(el));
}, this);
},
pushIn: function(){
this.fireEvent('in');
this.set('tween', {duration: 'short'});
this.tween('paddingLeft', '50px');
},
pushOut: function(){
this.fireEvent('out');
this.set('tween', {duration: 'short'});
this.tween('paddingLeft', '0px');
}
});
window.addEvent('domready', function(){
var p = new Pusher({
elements: $$('li')
});
p.addEvent('in', function(){ alert('in'); });
p.addEvent('out', function(){ alert('out'); });
});
</script>
而在HTML:
<ul id="mylist">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
我也试过如下:
window.addEvent('domready', function(){
var p = new Pusher({
elements: $$('li'),
onIn: function(){ alert('in'); },
onOut: function(){ alert('out'); }
});
});
我在做什么错?
太棒了,多好的答案。谢谢! – 2010-04-25 18:15:47
很高兴它为你工作。干杯! – Anurag 2010-04-25 22:09:53