mootools完成特效_使用MooTools,jQuery和Dojo完成常见任务

mootools完成特效

I've been dabbling with Dojo quite a bit lately. I feel great about my MooTools and jQuery skills but I'm a bit still raw when it comes to Dojo. What's important that I keep in mind, however, is that the tasks I'm trying to accomplish are the same -- the syntax is simply different. Here are a few basic JavaScript tasks and the syntax to accomplish them within each awesome framework.

最近我一直在和Dojo擦肩而过。 我对自己的MooTools和jQuery技能感到很满意,但是对于Dojo还是有点陌生​​。 但是,我要记住的重要一点是,我要完成的任务是相同的-语法完全不同。 以下是一些基本JavaScript任务以及在每个很棒的框架内完成这些任务的语法。

DOM准备就绪时执行代码 (Execute Code when the DOM is Ready)

Dojo工具包 (Dojo Toolkit)


dojo.ready(function() {
	//do stuff
});


jQuery的 (jQuery)


jQuery(document).ready(function() {
	//do stuff
});


Moo工具 (MooTools)


window.addEvent('domready',function() {
	//do stuff
});





收集元素 (Collect Elements)

Dojo工具包 (Dojo Toolkit)


var myElement = dojo.byId('myElement');
var divs = dojo.query('div');


jQuery的 (jQuery)


var myElement = jQuery('#myElement');
var divs = jQuery('div');


Moo工具 (MooTools)


var myElement = document.id('myElement');
var divs = $$('div');




创建事件监听器 (Create Event Listeners)

Dojo工具包 (Dojo Toolkit)


dojo.connect(dojo.byId('myElement'),'onclick',function() {
	alert('You clicked me!');
});


jQuery的 (jQuery)


jQuery('#myElement').click(function() {
	alert('You clicked me!');
});


Moo工具 (MooTools)


document.id('myElement').addEvent('click',function() {
	alert('You clicked me!');
});




创建一个新元素,注入Document.Body (Create a New Element, Inject Into Document.Body)

Dojo工具包 (Dojo Toolkit)


dojo.create('div',{
	innerHTML: 'This is a new element',
	id: 'myElement'
},dojo.body());


jQuery的 (jQuery)


jQuery('<div id="myElement">This is a new element</div>').appendTo('body');


Moo工具 (MooTools)


new Element('div',{
	id: 'myElement',
	text: 'This is a new element'
}).inject(document.body);




执行AJAX请求 (Execute AJAX Requests)

Dojo工具包 (Dojo Toolkit)


dojo.xhrPost({
	url: 'save.php',
	content: {
		id: dojo.byId('user-id').value
	}
	load: function(response) {
		alert('Received the following response:  ' + response);
	}
});


jQuery的 (jQuery)


jQuery.ajax({
	url: 'save.php',
	type: 'post',
	data: {
		id: jQuery('#user-id').val()
	},
	success: function(response) {
		alert('Received the following response:  ' + response);
	}
});


Moo工具 (MooTools)


new Request({
	url: 'save.php',
	method: 'post',
	data: {
		id: document.id('user-id').value
	},
	onSuccess: function(response) {
		alert('Received the following response:  ' + response);
	}
}).send();




动画元素的不透明度 (Animate the Opacity of an Element)

Dojo工具包 (Dojo Toolkit)


dojo.anim('myElement',{ opacity: 0.7 }, 250);


jQuery的 (jQuery)


jQuery('#myElement').fadeTo(250,0.7);
//duration first...ftl


Moo工具 (MooTools)


document.id('myElement').set('tween',{ duration: 250 }).fade(0.7);


See? Dojo, jQuery, and MooTools aren't that different. Same problems, different solution syntax. Like Pete Higgins says: It's just JavaScript!

看到? Dojo,jQuery和MooTools没什么不同。 同样的问题,不同的解决方案语法。 就像Pete Higgins所说:只是JavaScript!

翻译自: https://davidwalsh.name/mootools-jquery-dojo

mootools完成特效

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值