mootools_在MooTools 1.2中创建自定义事件

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插件中 ? 您有自己的自定义事件吗?

翻译自: https://davidwalsh.name/mootools-custom-event

mootools

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值