天下之事,必先处之难,而后易之。

JavaScript代码编写尝试使用Vanilla JS 或者Jquery插件

From Here: http://vanilla-js.com/

Vanilla JS is a fast, lightweight, cross-platform frameworkfor building incredible, powerful JavaScript applications.

Introduction

The Vanilla JS team maintains every byte of code in the framework and works hard each day to make sure it is small and intuitive. Who's using Vanilla JS? Glad you asked! Here are a few:

  • Facebook
  • Google
  • YouTube
  • Yahoo
  • Wikipedia
  • Windows Live
  • Twitter
  • Amazon
  • LinkedIn
  • MSN
  • eBay
  • Microsoft
  • Tumblr
  • Apple
  • Pinterest
  • PayPal
  • Reddit
  • Netflix
  • Stack Overflow

In fact, Vanilla JS is already used on more websites than jQuery, Prototype JS, MooTools, YUI, and Google Web Toolkit - combined.

Download

Ready to try Vanilla JS? Choose exactly what you need!

Options

Final size: 0 bytes uncompressed, 25 bytes gzipped. 

Testimonials

Vanilla JS makes everything an object, which is very convenient for OO JS applications.

Getting Started

The Vanilla JS team takes pride in the fact that it is the most lightweight framework available anywhere; using our production-quality deployment strategy, your users' browsers will have Vanilla JS loaded into memory before it even requests your site.

To use Vanilla JS, just put the following code anywhere in your application's HTML:

  1. <script src="path/to/vanilla.js"></script>

When you're ready to move your application to a production deployment, switch to the much faster method:

  1.  

That's right - no code at all. Vanilla JS is so popular that browsers have been automatically loading it for over a decade.

Speed Comparison

Here are a few examples of just how fast Vanilla JS really is:

Retrieve DOM element by ID

  Codeops / sec
Vanilla JS document.getElementById('test-table');
12,137,211
 
Dojo dojo.byId('test-table');
5,443,343
 
Prototype JS $('test-table')
2,940,734
 
Ext JS delete Ext.elCache['test-table']; Ext.get('test-table');
997,562
 
jQuery $jq('#test-table');
350,557
 
YUI YAHOO.util.Dom.get('test-table');
326,534
 
MooTools document.id('test-table');
78,802
 

Retrieve DOM elements by tag name

  Codeops / sec
Vanilla JS document.getElementsByTagName("span");
8,280,893
 
Prototype JS Prototype.Selector.select('span', document);
62,872
 
YUI YAHOO.util.Dom.getElementsBy(function(){return true;},'span');
48,545
 
Ext JS Ext.query('span');
46,915
 
jQuery $jq('span');
19,449
 
Dojo dojo.query('span');
10,335
 
MooTools Slick.search(document, 'span', new Elements);
5,457
 

Code Examples

Here are some examples of common tasks in Vanilla JS and other frameworks:

Fade an element out and then remove it

Vanilla JS var s = document.getElementById('thing').style; s.opacity = 1; (function fade(){(s.opacity-=.1)<0?s.display="none":setTimeout(fade,40)})();
jQuery <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> $('#thing').fadeOut(); </script>

Make an AJAX call

Vanilla JS
var r = new XMLHttpRequest(); 
r.open("POST", "path/to/api", true);
r.onreadystatechange = function () {
if (r.readyState != 4 || r.status != 200) return;
alert("Success: " + r.responseText); };
r.send("banana=yellow");
jQuery
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 

<script>

$.ajax({

    type: 'POST',

    url: "path/to/api",

    data: "banana=yellow",

    success: function (data) {

       alert("Success: " + data);

   }

});

</script>

Further Reading

For more information about Vanilla JS:

posted @ 2014-04-17 13:35  boonya  阅读(690)  评论(0编辑  收藏  举报
我有佳人隔窗而居,今有伊人明月之畔。
轻歌柔情冰壶之浣,涓涓清流梦入云端。
美人如娇温雅悠婉,目遇赏阅适而自欣。
百草层叠疏而有致,此情此思怀彼佳人。
念所思之唯心叩之,踽踽彳亍寤寐思之。
行云如风逝而复归,佳人一去莫知可回?
深闺冷瘦独自徘徊,处处明灯影还如只。
推窗见月疑是归人,阑珊灯火托手思忖。
庐居闲客而好品茗,斟茶徐徐漫漫生烟。

我有佳人在水之畔,瓮载渔舟浣纱归还。
明月相照月色还低,浅近芦苇深深如钿。
庐山秋月如美人衣,画堂春阁香气靡靡。
秋意幽笃残粉摇曳,轻轻如诉画中蝴蝶。
泾水潺潺取尔浇园,暮色黄昏如沐佳人。
青丝撩弄长裙翩翩,彩蝶飞舞执子手腕。
香带丝缕缓缓在肩,柔美体肤寸寸爱怜。
如水之殇美玉成欢,我有佳人清新如兰。
伊人在水我在一边,远远相望不可亵玩。