mootools
Javascript has a number of native events like "mouseover," "mouseout", "click", and so on. What if you want to create your own events though? Creating events using MooTools is as easy as it gets.
JavaScript具有许多本机事件,例如“ mouseover”,“ mouseout”,“ click”等。 但是,如果您想创建自己的事件该怎么办? 使用MooTools创建事件非常容易。
MooTools JavaScript (The MooTools JavaScript)
/* click - control event */
Element.Events.altClick = {
base: 'click',
condition: function(event) {
return event.alt; // alt key?
}
};
/* usage */
window.addEvent('domready',function() {
var ccs = 0, acd = $('alt-click-div');
acd.addEvent('altClick',function() {
acd.set('text','You have alt-clicked me ' + (++ccs) + ' times');
});
});
What's great about creating custom events in MooTools is that you need to give the Element.Events object as little information as you could imagine: a base to listen for the custom event for and a condition property that you return a Boolean value from if the condition matches your desired event.
在MooTools中创建自定义事件的最大好处是,您需要为Element.Events对象提供尽可能少的信息:一个监听自定义事件的基础,以及一个条件属性,如果条件满足,则返回一个布尔值符合您想要的事件。
When would you use alt-click? Maybe in my MooTools ContextMenu plugin? Do you have any custom events you live by?
什么时候使用alt点击? 也许在我的MooTools ContextMenu插件中 ? 您有自己的自定义事件吗?
mootools