mootools_在MooTools 1.2中实现基本和精美的显示/隐藏

mootools

One of the great parts of MooTools is that the library itself allows for maximum flexibility within its provided classes. You can see evidence of this in the "Class" class' implement method. Using the implement method, you can add your own methods to custom or core classes.

MooTools的一大优点是库本身允许在其提供的类中提供最大的灵活性。 您可以在“类”类的实现方法中看到这一点的证据。 使用Implement方法,可以将自己的方法添加到自定义或核心类。

I've created a really basic example and more advanced example of implementing show and hide on the Element class. By implementing show and hide, I can call show() and hide() on any element of any type that I want!

我已经创建了一个非常基本的示例,并在Element类上实现了显示和隐藏的更高级的示例 。 通过实现show和hide,我可以在我想要的任何类型的任何元素上调用show()和hide() !

基本示例-MooTools JavaScript (Basic Example - MooTools JavaScript)


//when the dom is ready...
window.addEvent('domready', function() {
	//time to implement basic show / hide
	Element.implement({
		//implement show
		show: function() {
			this.setStyle('display','');
		},
		//implement hide
		hide: function() {
			this.setStyle('display','none');
		}
	});
});


基本示例-XHTML /用法 (Basic Example - XHTML / Usage)


<p>
	<strong>Basic: </strong><a href="javascript:$('blove').show();">Show</a> | <a href="javascript:$('blove').hide();">Hide</a><br />
	<img src="/demo/beatles-love.jpg" id="blove" />
</p>

As you can see, the links call the image element's show and hide methods.

如您所见,这些链接调用了图像元素的show和hide方法。

花式示例-MooTools JavaScript (Fancy Example - MooTools JavaScript)


//when the dom is ready...
window.addEvent('domready', function() {
	//time to implement fancy show / hide
	Element.implement({
		//implement show
		fancyShow: function() {
			this.fade('in');
		},
		//implement hide
		fancyHide: function() {
			this.fade('out');
		}
	});
});


花式示例-XHTML /用法 (Fancy Example - XHTML / Usage)


<p>
	<strong>Fancy: </strong><a href="javascript:$('blove2').fancyShow();">Show</a> | <a href="javascript:$('blove2').fancyHide();">Hide</a><br />
	<img src="/demo/beatles-love.jpg" id="blove2" />
</p>

Instead of the not-so-subtle show and hide that we used in the basic example, I've chosen to use a softer fade in and fade out effect. Implementing methods is that easy!

我选择了使用更柔和的淡入和淡出效果,而不是我们在基本示例中使用的不太细腻的显示和隐藏。 实现方法就这么简单!

翻译自: https://davidwalsh.name/mootools-show-hide

mootools

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值