-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
1251 lines (795 loc) · 61.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Winter Bud</title>
<meta name="author" content="wibud">
<meta name="description" content="前端 | Comments Touch标准草案整理 touch事件 现在对于touch事件还没有正式标准出来的,只有一个推荐草案,看草案戳这里。当然,没有正式标准不代表没有浏览器支持,目前很多浏览器是可以支持touch的,可以从caniuse上看一下具体的支持情况 支持情况戳这里。 …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/atom.xml" rel="alternate" title="Winter Bud" type="application/atom+xml">
<link rel="canonical" href="http://wibud.github.io/">
<link href="/favicon.png" rel="shortcut icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<link href="/stylesheets/font-awesome.min.css" media="screen, projection" rel="stylesheet" type="text/css">
<!--[if lt IE 9]><script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<script src="/javascripts/libs/jquery.min.js"></script>
</head>
<body>
<div class="container">
<div class="left-col">
<div class="intrude-less">
<header id="header" class="inner"><div class="profilepic">
<script src="/javascripts/md5.js"></script>
<script type="text/javascript">
$(function(){
$('.profilepic').append("<img src='/images/avator.jpeg' alt='Profile Picture' style='width: 160px;' />");
});
</script>
</div>
<nav id="main-nav">
<section class="aboutme">
<i>Winter Bud</i>
<p>
UED程序猿;专业前端,业余JAVA;爱鼓捣、瞎折腾;讲的了段子,写的了代码
</p>
</section>
<ul class="main">
<li><a href="/">Blog</a></li>
<li><a href="/about">About</a></li>
<li><a href="/blog/archives">Archives</a></li>
</ul>
</nav>
<nav id="sub-nav">
<div class="social">
<a class="email" href="mailto:[email protected]" title="Email">Email</a>
<a class="github" href="https://github.com/wibud" title="GitHub">GitHub</a>
<a class="rss" href="/atom.xml" title="RSS">RSS</a>
<a class="weibo" href="http://weibo.com/u/2435540027" title="weibo">Weibo</a>
</div>
</nav>
</header>
</div>
</div>
<div class="mid-col">
<div class="mid-col-container">
<div id="content" class="inner">
<div itemscope itemtype="http://schema.org/Blog">
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2015-04-10T21:23:17+08:00" data-updated="true" itemprop="datePublished"></time></div>
<div class="tags">
<a class='category' href='/blog/categories/qian-duan/'>前端</a>
</div>
| <a href="/blog/2015/04/10/touchbiao-zhun-cao-an-zheng-li/#comments">Comments</a>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2015/04/10/touchbiao-zhun-cao-an-zheng-li/" itemprop="url">Touch标准草案整理</a></h1>
<div class="entry-content" itemprop="articleBody">
<h1>touch事件</h1>
<p>现在对于touch事件还没有正式标准出来的,只有一个推荐草案,<a href="http://www.w3.org/TR/touch-events/">看草案戳这里</a>。当然,没有正式标准不代表没有浏览器支持,目前很多浏览器是可以支持touch的,可以从caniuse上看一下具体的支持情况</p>
<p><img src="http://gtms01.alicdn.com/tps/i1/TB1jPv4FFXXXXXnaXXXHXUOSFXX-938-375.jpg" alt="" /></p>
<p><a href="http://caniuse.com/#search=touch">支持情况戳这里</a>。</p>
<p>详细了解touch事件,还是很有必要看一下草案的(全英文好烦。。。心里一万头草泥马呼啸而过)</p>
<p>首先看一下两个概念,便于之后的阅读:</p>
<ul>
<li>touch point(触点):说白了就是咱手指点触摸屏时,与屏幕接触的那个坐标点</li>
<li>active touch point(活跃触点):当前在屏幕上,且可以被浏览器追踪(捕获)到的触点。详细说来,当从一个触点上触发了touchstart事件,触点就激活了,变身成为活跃触点了,当在触点上触发了touchend和touchcancel事件时,触点就被移除或者不在被浏览器追踪了,此时这个活跃触点就挂掉了。</li>
</ul>
<h2>定义接口对象</h2>
<h3>Touch:</h3>
<blockquote><p>描述touch point(触点)的对象。Touch对象创建之后,属性不可修改。</p></blockquote>
<pre><code>interface Touch {
readonly attribute long identifier;
readonly attribute EventTarget target;
readonly attribute long screenX;
readonly attribute long screenY;
readonly attribute long clientX;
readonly attribute long clientY;
readonly attribute long pageX;
readonly attribute long pageY;
};
</code></pre>
<blockquote><p>Attributes属性详解:</p></blockquote>
<ul>
<li><p>clientX:触点相对视口的水平坐标(像素),不包括任何滚动偏移量</p></li>
<li><p>clientY:触点相对视口的垂直坐标(像素),不包括任何滚动偏移量</p></li>
<li><p>identifier:touch point(触点)的唯一识别码。当一个触点被激活(active touch point)时,它会被分配一个标示符,用于区分其他激活的触点(多点触摸的情景)当触点保持活跃(啥叫保持活跃?手指头放到屏幕上不离开,所对应的触点就一直是活跃的,不管咱是手指点着不动,还是不断滑动。当然触发touchcancel的话就不在这个范畴内了),引用到它的所有事件必须为其分配相同的标识符,保证每个触点有唯一的标示符。</p></li>
<li><p>pageX:触点相对视口的水平坐标(像素),包括滚动偏移量</p></li>
<li><p>pageY:触点相对视口的垂直坐标(像素),包括滚动偏移量</p></li>
<li><p>screenX:触点相对屏幕的水平坐标(像素)</p></li>
<li><p>screenY:触点相对屏幕的垂直坐标(像素)</p></li>
<li><p>target:eventtarget,和其他事件的target一样</p></li>
</ul>
<h3>TouchList</h3>
<blockquote><p>定义了Touch对象的列表,不可修改,支持索引</p></blockquote>
<pre><code>interface TouchList {
readonly attribute unsigned long length;
getter Touch? item (unsigned long index);
};
</code></pre>
<blockquote><p>Attributes:</p></blockquote>
<ul>
<li>length:不解释,都知道的</li>
</ul>
<blockquote><p>Metods:</p></blockquote>
<ul>
<li>item:返回索引值对应的Touch对象</li>
</ul>
<a href="/blog/2015/04/10/touchbiao-zhun-cao-an-zheng-li/" class="more-link">Read on →</a>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2015-03-21T16:12:08+08:00" data-updated="true" itemprop="datePublished"></time></div>
<div class="tags">
<a class='category' href='/blog/categories/qian-duan/'>前端</a>
</div>
| <a href="/blog/2015/03/21/chu-shi-react/#comments">Comments</a>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2015/03/21/chu-shi-react/" itemprop="url">初识react</a></h1>
<div class="entry-content" itemprop="articleBody">
<h2>是什么</h2>
<blockquote><p>React is a JavaScript library for creating user interfaces by Facebook and Instagram. Many people choose to think of React as the V in MVC.</p>
<p>We built React to solve one problem: building large applications with data that changes over time. To do this, React uses two main ideas.</p></blockquote>
<p>套用官网的一句话</p>
<blockquote><p>React可以被认为是MVC中得View层。它是用来构建数据不断变化的大型发杂应用的。</p></blockquote>
<p>所以不要拿React同Angular等框架作比较了,它只是View层的框架,没有什么可比性~~</p>
<p>在React中,贯穿始终的就是<code>组件</code>(组件化也是web发展的方向),React组件可以简单的认为是HTML和JavaScript的组合,通常的View层是使用一些模板工具生成,而React是通过组件的组合产出View,每个组件都可以独立或者配合使用(组件定义良好的话),其中React提供了一系列创建组件、渲染组件的方法,同时也对事件、状态等进行了封装。</p>
<p>为什么说React适合数据频繁变化的应用呢?</p>
<ul>
<li>数据变化时,只需更新组件的状态,剩下的操作React都帮你做了</li>
<li>React创造性的虚拟DOM和diff算法,使得其比传统的DOM更新更加高效,性能也更高</li>
</ul>
<p>这里不得不提一下<a href="http://facebook.github.io/jsx/">JSX</a>,它是和React配合使用的,当然不用也可以的(follow your heart~)。</p>
<blockquote><p>JSX 是一个看起来很像 XML 的 JavaScript 语法扩展。React 可以用来做简单的 JSX 句法转换。</p></blockquote>
<p>简单说来,JSX就是可以将JavaScript 语法写成XML/HTML的那个样子,举个简单的例子:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="c1">// 输入 (JSX):</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">app</span> <span class="o">=</span> <span class="o"><</span><span class="nx">Nav</span> <span class="nx">color</span><span class="o">=</span><span class="s2">"blue"</span> <span class="o">/></span><span class="p">;</span>
</span><span class='line'><span class="c1">// JSX 把类 XML 的语法转成原生 JavaScript,XML 元素、属性和子节点被转换成 React.createElement 的参数。</span>
</span><span class='line'><span class="c1">// 经JSX转化,输出 (JS):</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">app</span> <span class="o">=</span> <span class="nx">React</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="nx">Nav</span><span class="p">,</span> <span class="p">{</span><span class="nx">color</span><span class="o">:</span><span class="s2">"blue"</span><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>
<h2>为什么</h2>
<p>我是否该使用React?别急,下面我们来详细看下。</p>
<h3>优点</h3>
<ul>
<li>只需要声明怎么展示,数据变化时,React自动帮你处理,不需要关心怎么更新DOM</li>
<li>React唯一需要做的就是构建组件,组件良好的封装性,更易于代码复用和关注分离</li>
<li>只需要查看组件的返回就能知道组件是如何渲染的,而不需要知道HTML和JS处理逻辑</li>
<li>方便维护和扩展</li>
</ul>
<h3>缺点</h3>
<ul>
<li>学习成本虽然不高,但是要理解和熟练掌握还是要花一定的时间,主要是官方文档错综发杂</li>
<li>React很年轻,社区也在发展中,相应的组件库并不丰富</li>
<li>React只是View层,实现一些复杂应用可能需要其他框架的支持</li>
</ul>
<h2>怎么用</h2>
<h3>如何显示</h3>
<p>先来看一个官网上的简单例子:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="cp"><!DOCTYPE html></span>
</span><span class='line'><span class="nt"><html></span>
</span><span class='line'> <span class="nt"><head></span>
</span><span class='line'> <span class="nt"><title></span>Hello React<span class="nt"></title></span>
</span><span class='line'> <span class="nt"><script </span><span class="na">src=</span><span class="s">"http://fb.me/react-0.13.0.js"</span><span class="nt">></script></span>
</span><span class='line'> <span class="nt"><script </span><span class="na">src=</span><span class="s">"http://fb.me/JSXTransformer-0.13.0.js"</span><span class="nt">></script></span>
</span><span class='line'> <span class="nt"></head></span>
</span><span class='line'> <span class="nt"><body></span>
</span><span class='line'> <span class="nt"><div</span> <span class="na">id=</span><span class="s">"example"</span><span class="nt">></div></span>
</span><span class='line'> <span class="nt"><script </span><span class="na">type=</span><span class="s">"text/jsx"</span><span class="nt">></span>
</span><span class='line'>
</span><span class='line'> <span class="kd">var</span> <span class="nx">HelloWorld</span> <span class="o">=</span> <span class="nx">React</span><span class="p">.</span><span class="nx">createClass</span><span class="p">({</span>
</span><span class='line'>
</span><span class='line'> <span class="nx">render</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="k">return</span> <span class="p">(</span>
</span><span class='line'> <span class="o"><</span><span class="nx">p</span><span class="o">></span>
</span><span class='line'> <span class="nx">Hello</span><span class="p">,</span> <span class="o"><</span><span class="nx">input</span> <span class="nx">type</span><span class="o">=</span><span class="s2">"text"</span> <span class="nx">placeholder</span><span class="o">=</span><span class="s2">"Your name here"</span> <span class="o">/>!</span>
</span><span class='line'> <span class="nx">It</span> <span class="nx">is</span> <span class="p">{</span><span class="k">this</span><span class="p">.</span><span class="nx">props</span><span class="p">.</span><span class="nx">date</span><span class="p">.</span><span class="nx">toTimeString</span><span class="p">()}</span>
</span><span class='line'> <span class="o"><</span><span class="err">/p></span>
</span><span class='line'> <span class="p">);</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'> <span class="p">});</span>
</span><span class='line'>
</span><span class='line'> <span class="nx">setInterval</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">React</span><span class="p">.</span><span class="nx">render</span><span class="p">(</span>
</span><span class='line'> <span class="o"><</span><span class="nx">HelloWorld</span> <span class="nx">date</span><span class="o">=</span><span class="p">{</span><span class="k">new</span> <span class="nb">Date</span><span class="p">()}</span> <span class="o">/></span><span class="p">,</span>
</span><span class='line'> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s1">'example'</span><span class="p">)</span>
</span><span class='line'> <span class="p">);</span>
</span><span class='line'> <span class="p">},</span> <span class="mi">500</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'> <span class="nt"></script></span>
</span><span class='line'> <span class="nt"></body></span>
</span><span class='line'><span class="nt"></html></span>
</span></code></pre></td></tr></table></div></figure>
<p>在浏览器中运行这个例子,时间是每隔半秒钟变化一次。在输入框输入内容,你会发现 React 在用户界面中只改变了时间, 任何你在输入框输入的内容一直保留着,React知道哪些东西改变了,知道要更新哪些东西,并且帮你做好了。</p>
<p>其中用到了JSX,使用JSX的话,需要用<code><script type="text/jsx"></code>标签包裹JSX代码。</p>
<p>对这个组件的输入称为 props - “properties”的缩写。得益于 JSX 语法,它们通过参数传递。不要去修改props的值, this.props 是只读的。</p>
<p>React 组件非常简单。你可以认为它们就是简单的函数,接受 props 和 state (后面会讨论) 作为参数,然后渲染出 HTML。正是应为它们是这么的简单,这使得它们非常容易理解。</p>
<a href="/blog/2015/03/21/chu-shi-react/" class="more-link">Read on →</a>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2014-12-01T00:14:36+08:00" data-updated="true" itemprop="datePublished"></time></div>
<div class="tags">
<a class='category' href='/blog/categories/qian-duan/'>前端</a>
</div>
| <a href="/blog/2014/12/01/dive-into-requestanimationframe/#comments">Comments</a>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2014/12/01/dive-into-requestanimationframe/" itemprop="url">Dive Into requestAnimationFrame</a></h1>
<div class="entry-content" itemprop="articleBody">
<h2>介绍</h2>
<p>requestAnimationFrame(以下简称raf)方法,字面意思上看是:请求动画帧;较官方的解释是:通知在系统准备好绘制动画帧时调用该帧,从而为创建动画网页提供了一种更平滑更高效的方法;那通俗一点就是:告诉浏览器说 “我这里有一帧(一些操作),需要你帮我绘制(执行)一下”,“ok,没问题,我挑个合适的时机给你绘制这一帧(执行这些操作)”</p>
<p><img src="/images/private/raf-1.jpg" alt="" /></p>
<ul>
<li><p>一、浏览器的绘制(执行)时机是嘛时候</p>
<p> 首先,我们需要了解的是,页面的绘制由CPU或者GPU进行的,但是其绘制频率受限于我们的显示器的刷新频率,一般显示器的刷新频率是60HZ,所以对应于绘制频率最高就是60fps(frame per second)。于是60fps也成了检验性能的一个重要的指标,be closer be better,通常来说,在30fps到60fps之间都是可以接受的。</p>
<p> 60fps意味着我们执行每一帧的时间只有大约16.7ms(1000/60),这也是常见的使用setTimeout和setInterval实现动画时所设置的间隔时间。那对于raf来说呢,我们将绘制(执行)时机交给了浏览器自己进行判断,浏览器在合适的时机来绘制(执行)我们提供给浏览器的帧(操作)。浏览器如何决定这个合适时机的呢?(均基于chrome环境)</p>
<blockquote><p>raf最大的调用频率不会超过60fps</p></blockquote>
<p> 主观上来说,60fps已经达到了很好效果,没必要用到更快的更新频率了。貌似这一点也是chromium对于raf的设计原则之一,为了印证这一结论,特地去扒了扒chromium中raf的执行流程</p>
<p> <img src="/images/private/chromium-request-anim-frame.png" alt="" /></p>
<p> 从流程图可以看到</p>
<pre><code> if (animation update pending and >= 16ms since last update)
post task to anticipate next frame
else
post task to retry in (next_frame - now)ms
</code></pre>
<p> 如果有等待的animation更新且距离上一次更新超过16ms,则会post task,来准备下一帧,也就是说</p>
<blockquote><p>针对chrome而言,无论屏幕的刷新频率是多少,raf回调函数的执行频率不会超过60次/秒</p></blockquote>
<p> 找了大量的资料也没有找到raf回调的执行时机是如何计算的,唯一的途径只有看源码了,不过源码是C++,出了大学课堂就再没用过,全忘干净了。。。,大体看了看,貌似原理是:如果上一次raf的回调执行时间过长,那么触发下一次raf回调的时间就会缩短,反之亦然,目的是保证动画不丢帧。(如有错误,请轻拍~~)</p>
<p> 其实,raf不需要关心屏幕什么时候刷新,也并不是在屏幕刷新的时候进行绘制,而是保证在屏幕刷新间隔内不会有两个帧的绘制而导致前一个帧丢失。</p></li>
</ul>
<a href="/blog/2014/12/01/dive-into-requestanimationframe/" class="more-link">Read on →</a>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2014-11-03T00:10:52+08:00" data-updated="true" itemprop="datePublished"></time></div>
<div class="tags">
<a class='category' href='/blog/categories/qian-duan/'>前端</a>
</div>
| <a href="/blog/2014/11/03/yi-gpu-accelerated-compositing-in-chrome(gpuhe-cheng-jia-su-)/#comments">Comments</a>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2014/11/03/yi-gpu-accelerated-compositing-in-chrome(gpuhe-cheng-jia-su-)/" itemprop="url">GPU Accelerated Compositing in Chrome(GPU加速合成)</a></h1>
<div class="entry-content" itemprop="articleBody">
<blockquote><p>原文地址:<a href="http://www.chromium.org/developers/design-documents/gpu-accelerated-compositing-in-chrome">http://www.chromium.org/developers/design-documents/gpu-accelerated-compositing-in-chrome</a></p>
<p>作者:Tom Wiltzius, Vangelis Kokkevis & the Chrome Graphics team</p>
<p>其中包含个人理解,如有出入,请轻拍!</p></blockquote>
<p>先来简单的总结下!</p>
<p>硬件(GPU)加速加速的是啥?是层的合成(layer composite),所以有些说使用translate3D打开硬件加速的说法是不恰当的,GPU加速是一直在的(在有GPU且设备的图形驱动可用的情况下),在chrome中,使用translate3D其实是使该元素拥有独立的GraphicsLayer,那拥有独立的GraphicsLayer有啥好处呢?简单来说有如下几点:</p>
<ul>
<li>每个GraphicsLayer都有一个GraphicsContext,GraphicsContext会输出该层的位图,交由GPU合成,比CPU要快</li>
<li>当需要repaint时,只需要repaint自己,不会影响到其他的GraphicsLayer。repaint完之后,只需要通过GPU同其他层合并下(composite layers)</li>
<li>对于CSS动画,不需要repaint</li>
</ul>
<p>下面简单介绍下chrome的渲染原理,详细了解可看下面译文或者直接读原文:</p>
<p>在chrome中为render服务的有4种树形结构,我们熟知的DOM树是其中之一,其他的三个分别是:</p>
<ul>
<li><p>RenderObject Tree</p>
<p> 由RenderObject构成,RenderObject同DOM树中得Node节点一一对应,RenderObject知道如何去paint(paint != draw)其对应的Node。</p></li>
<li><p>RenderLayers Tree</p>
<p> 由RenderLayer构成,RenderLayer同RenderObject是一对多的关系,满足如下条件的RenderObject拥有新的RenderLayer,而其他的RenderObject就和它的第一个拥有独立RenderLayer的父元素公用一个RenderLayer。</p>
<ul>
<li>页面的根节点的RenderObject</li>
<li>有明确的CSS定位属性(relative,absolute或者transform)</li>
<li>是透明的</li>
<li>有CSS overflow、CSS alpha遮罩(alpha mash)或者CSS reflection</li>
<li>有CSS 滤镜(fliter)</li>
<li>3D环境或者2D加速环境的canvas元素对应的RenderObject</li>
<li>video元素对应的RenderObject</li>
</ul>
</li>
<li><p>GraphicsLayers Tree</p>
<p> 由GraphicsLayer构成,GraphicsLayer同RenderLayer的关系和RenderLayer同RenderObject的关系是一样的。满足如下条件的RenderLayer会拥有新的GraphicsLayer。</p>
<ul>
<li>有3D或者perspective transform的CSS属性的层</li>
<li>使用加速视频解码的video元素的层</li>
<li>3D或者加速2D环境下的canvas元素的层</li>
<li>插件,比如flash(Layer is used for a composited plugin)</li>
<li>对opacity和transform应用了CSS动画的层</li>
<li>使用了加速CSS滤镜(filters)的层</li>
<li>有合成层后代的层</li>
<li>同合成层重叠,且在该合成层上面(z-index)渲染的层</li>
</ul>
<p> 每个GraphicsLayer都有一个GraphicsContext,GraphicsContext会负责输出该层的位图,位图是存储在共享内存中,作为纹理上传到GPU中,最后由GPU将多个位图进行合成,然后draw到屏幕上。</p>
<p> 需要注意的是</p>
<blockquote><p>GraphicsLayer是消耗内存资源的</p></blockquote>
<p> 所以说,对于像translate3D这样的hack不要过度使用,尤其是在手机上,大部分手机的显存和内存是共享的,GraphicsLayer过多导致内存占用过多的话,会使手机变卡的。</p></li>
</ul>
<p>在chrome为渲染服务的有两个进程:Render进程和GPU进程。GPU进程负责Render进程和GPU之间的命令的传递,Render进程包括主线程和合成线程,在chrome中,paint和composite放在了合成线程中。</p>
<a href="/blog/2014/11/03/yi-gpu-accelerated-compositing-in-chrome(gpuhe-cheng-jia-su-)/" class="more-link">Read on →</a>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2014-01-09T15:17:48+08:00" data-updated="true" itemprop="datePublished"></time></div>
<div class="tags">
<a class='category' href='/blog/categories/js/'>js</a>, <a class='category' href='/blog/categories/qian-duan/'>前端</a>
</div>
| <a href="/blog/2014/01/09/javascriptyan-ge-mo-shi-xiang-jie/#comments">Comments</a>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2014/01/09/javascriptyan-ge-mo-shi-xiang-jie/" itemprop="url">JavaScript严格模式详解</a></h1>
<div class="entry-content" itemprop="articleBody">
<h2>一、简介</h2>
<p>严格模式(strict mode)是在ES5(ECMAScript 5)中引入的一种新的JavaScript运行模式,该模式下,禁止了很多JavaScript中问题较多、容易出错、影响应能的特性,目的是让JavaScript在更为严格的条件下运行,减少怪异行为和语言不合理的地方,提高编译运行性能(比如禁用with语句),增强了代码本身的安全性。</p>
<p>在ES5之前的版本是不支持严格模式的,但是严格模式有很好的向后兼容性,因为低版本标准的引擎会忽略严格模式的声明,这个会在之后进行介绍。</p>
<p>想了解各浏览器对于严格模式的支持情况戳这里<a href="http://kangax.github.io/es5-compat-table/">ECMAScript 5 compatibility table</a>,其中还统计了ES5新增特性的兼容情况。</p>
<h2>二、声明</h2>
<p>声明调用严格模式十分简单,也有些怪异,使用字符串字面量:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="s2">"use strict"</span><span class="p">;</span>
</span></code></pre></td></tr></table></div></figure>
<p>之所以使用字符串字面量好处就是可以向后兼容,对于不支持严格模式的引擎,执行这条语句没有任何作用和影响。当然,如果我们使用了严格模式,那么就需要使用支持严格模式的引擎进行测试,使用低版本的引擎无法检测出严格模式下的错误。</p>
<p>声明方式有如下两种:</p>
<ul>
<li>1、声明整个脚本</li>
</ul>
<p>将<code>"use strict;"</code>在脚本文件第一行,且必须是第一行,否则严格模式将无效。</p>
<blockquote><p>在<code>"use strict;"</code>前不能有任何执行语句,即使是一个空的分号,都会使严格模式失效。</p></blockquote>
<p><code><script></code>包含的脚本块和引入的外部文件对于严格模式来说都是相互独立的,也就是说,一个脚本块或脚本文件设置成严格模式执行,并不会影响到其他的脚本块和脚本文件。</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="o"><</span><span class="nx">script</span><span class="o">></span>
</span><span class='line'> <span class="s2">"use strict"</span><span class="p">;</span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"严格模式"</span><span class="p">);</span>
</span><span class='line'><span class="o"><</span><span class="err">/script></span>
</span><span class='line'><span class="o"><</span><span class="nx">script</span><span class="o">></span>
</span><span class='line'> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"正常模式"</span><span class="p">);</span>
</span><span class='line'><span class="o"><</span><span class="err">/script></span>
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>2、声明单个函数体</li>
</ul>
<p>单个函数的声明和整个脚本的类似,需要将<code>"use strict;"</code>放在函数体的第一行。这样该函数就会以严格模式运行。</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">function</span> <span class="nx">f</span><span class="p">(){</span>
</span><span class='line'> <span class="s2">"use strict"</span><span class="p">;</span>
</span><span class='line'> <span class="c1">// ...</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<a href="/blog/2014/01/09/javascriptyan-ge-mo-shi-xiang-jie/" class="more-link">Read on →</a>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2013-12-20T17:52:00+08:00" data-updated="true" itemprop="datePublished"></time></div>
<div class="tags">
<a class='category' href='/blog/categories/gu-dao/'>鼓捣</a>
</div>
| <a href="/blog/2013/12/20/octopresszhu-ti/#comments">Comments</a>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2013/12/20/octopresszhu-ti/" itemprop="url">Octopress主题</a></h1>
<div class="entry-content" itemprop="articleBody">
<p>在Octopress默认主题的基础上进行了一些修改,把nav移到了顶端,同时在左侧增加了展示用户信息的sidebar。当浏览器宽度小于1152时,添加了响应式的布局。</p>
<p>源码地址:<a href="https://github.com/wibud/Octopress-Theme-WinterBud">github</a></p>
<p>如果对主题感兴趣,安装方式如下:</p>
<pre><code>$ cd octopress
$ git clone git://github.com/wibud/Octopress-Theme-WinterBud.git .themes/WinterBud
$ rake install['WinterBud']
$ rake generate
</code></pre>
<p><img src="/images/private/blog-screen.png" alt="" /></p>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2013-08-05T11:12:00+08:00" data-updated="true" itemprop="datePublished"></time></div>
<div class="tags">
<a class='category' href='/blog/categories/qian-duan/'>前端</a>
</div>
| <a href="/blog/2013/08/05/gethe-postqing-qiu/#comments">Comments</a>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2013/08/05/gethe-postqing-qiu/" itemprop="url">GET和POST请求</a></h1>
<div class="entry-content" itemprop="articleBody">
<h3>GET请求</h3>
<p>GET是最常见的请求类型,最常用于向服务器查询信息。如果要发送信息给服务器的话,需要将查询字符串参数追加到URL的末尾。</p>
<p>使用GET请求经常会发生一个错误,就是查询字符串参数的格式有问题。对于Javascript来说查询字符串中每个参数的名称和值都必须使用<code>encodeURIComponent()</code>进行编码,然后才能放到URL的末尾。</p>
<h3>POST请求</h3>
<p>POST通常用于向服务器发送应该被保存的数据。POST请求把数据作为请求的主体提交。POST请求的主体可以包含非常多的数据,而且格式不限。</p>
<h3>GET和POST的区别</h3>
<ul>
<li>GET只要是用来查询数据;POST主要用来提交数据</li>
<li>GET提交的数据是缀到URL末尾的,GET方式值发送HTTP消息头,没有消息体;POST的提交的数据是在消息体中</li>
<li>GET提交的数据量小,因为URL长度有限制;POST能提交大量数据</li>
<li>GET消耗的资源少;POST消耗的资源多</li>
</ul>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2013-08-03T11:11:00+08:00" data-updated="true" itemprop="datePublished"></time></div>
<div class="tags">
<a class='category' href='/blog/categories/js/'>js</a>, <a class='category' href='/blog/categories/qian-duan/'>前端</a>
</div>
| <a href="/blog/2013/08/03/cookieyu-session/#comments">Comments</a>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2013/08/03/cookieyu-session/" itemprop="url">Cookie与session</a></h1>
<div class="entry-content" itemprop="articleBody">
<h2>Cookie</h2>
<p>HTTP Cookie,通常直接叫做cookie,是在客户端用户存储会话信息的。cookie存储的信息是由服务器经HTTP头作为响应发给客户端的。例如服务器相应可能如下:</p>
<pre><code>HTTP/1.1 200 OK
Content-type:text/html
Set-Cookie:name=value
</code></pre>
<p>其中的<code>Set-Cookie</code>包含着会话信息,浏览器会存储这些会话信息,之后会为每个请求添加Cookie HTTP头,将信息发送回服务器,如下</p>
<pre><code>GET /index.html HTTP/1.1
Cookie:name=value
</code></pre>
<p>因为Cookie是存储在浏览器上,浏览器资源有限,所以Cookie的个数和大小会有限制,不同的浏览器对Cookie 的限制不同,有的限制每个域只能有20个Cookie,且每个域Cookie总大小限制在4095B,有的浏览器可能会多些。</p>
<h3>Cookie构成</h3>
<ul>
<li>名称:唯一确定cookie,名称是不区分大小写的</li>
<li>值:存储在cookie中的字符串的值,必须被URL编码</li>
<li>域:表示cookie对哪个域是有效的,所有向该有效域发送的请求都会加上这个cookie信息。如果没有设置,默认是设置cookie的域</li>
<li>路径:对于制定域中的那个路径,应该向服务器发送cookie</li>
<li>失效时间:表示cookie应该何时被删除。如果不设定,默认情况下,浏览器会话结束就会删除cookie(会话cookie)。如果设置了时间(大于当前时间),则浏览器关闭后cookie依然会保存在用户机器上(持久cookie)。这个值是GMT格式的日期。</li>
<li>安全标志</li>
</ul>
<h3>Javascript操作cookie</h3>
<p> <code>document.cookie</code>属性返回当前页面可用的(根据cookie的域、路径、失效时间和安全设置)所有cookie的字符串,一系列由分号分隔的名值对,如下:</p>
<pre><code>name1=value1;name2=value2;name3=value3
</code></pre>
<p>所有名字和值都是URL编码的,所以必须使用<code>decodeURIComponent()</code>解码。</p>
<p>设置值得时候,可以直接给<code>document.cookie</code>属性赋值,并不会覆盖cookie,除非设置的cookie名称已经存在。</p>
<p>由于cookie操作比较麻烦,并不直观,下面来看一个简化cookie操作的功能对象:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'> <span class="kd">var</span> <span class="nx">CookieUtil</span><span class="o">=</span><span class="p">{</span>
</span><span class='line'>
</span><span class='line'> <span class="nx">get</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">name</span><span class="p">){</span>
</span><span class='line'> <span class="kd">var</span> <span class="nx">cookieName</span> <span class="o">=</span> <span class="nb">encodeURIComponent</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span><span class="o">+</span><span class="s2">"="</span><span class="p">,</span>
</span><span class='line'> <span class="nx">cookieStart</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">cookie</span><span class="p">.</span><span class="nx">indexof</span><span class="p">(</span><span class="nx">cookieName</span><span class="p">);</span>
</span><span class='line'> <span class="nx">cookieValue</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'> <span class="k">if</span><span class="p">(</span><span class="nx">cookieStart</span> <span class="o">></span> <span class="o">-</span><span class="mi">1</span><span class="p">){</span>
</span><span class='line'> <span class="kd">var</span> <span class="nx">cookieEnd</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">cookie</span><span class="p">.</span><span class="nx">indexof</span><span class="p">(</span><span class="s2">";"</span><span class="p">,</span><span class="nx">cookieStart</span><span class="p">);</span>
</span><span class='line'> <span class="k">if</span><span class="p">(</span><span class="nx">cookieEnd</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">){</span>
</span><span class='line'> <span class="nx">cookieEnd</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">cookie</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'> <span class="nx">cookieValue</span> <span class="o">=</span> <span class="nb">decodeURIComponent</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">cookie</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="nx">cookieStart</span><span class="o">+</span><span class="nx">cookieName</span><span class="p">.</span><span class="nx">length</span><span class="p">,</span> <span class="nx">cookieEnd</span><span class="p">));</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="k">return</span> <span class="nx">cookieValue</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="nx">set</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">expires</span><span class="p">,</span> <span class="nx">path</span><span class="p">,</span> <span class="nx">domain</span><span class="p">,</span> <span class="nx">secure</span><span class="p">){</span>
</span><span class='line'> <span class="kd">var</span> <span class="nx">cookieText</span> <span class="o">=</span> <span class="nb">encodeURIComponent</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span><span class="o">+</span><span class="s2">"="</span><span class="o">+</span><span class="nb">encodeURIComponent</span><span class="p">(</span><span class="nx">value</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'> <span class="k">if</span><span class="p">(</span><span class="nx">expires</span> <span class="k">instanceof</span> <span class="nb">Date</span><span class="p">){</span>
</span><span class='line'> <span class="nx">cookieText</span> <span class="o">+=</span> <span class="s2">"; expires="</span> <span class="o">+</span> <span class="nx">expires</span><span class="p">.</span><span class="nx">toGMTString</span><span class="p">();</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="k">if</span><span class="p">(</span><span class="nx">path</span><span class="p">){</span>
</span><span class='line'> <span class="nx">cookieText</span> <span class="o">+=</span> <span class="s2">"; path="</span> <span class="o">+</span> <span class="nx">path</span><span class="p">;</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="k">if</span><span class="p">(</span><span class="nx">domain</span><span class="p">){</span>
</span><span class='line'> <span class="nx">cookieText</span> <span class="o">+=</span> <span class="s2">"; domain="</span> <span class="o">+</span> <span class="nx">domain</span><span class="p">;</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="k">if</span><span class="p">(</span><span class="nx">secure</span><span class="p">){</span>
</span><span class='line'> <span class="nx">cookieText</span> <span class="o">+=</span> <span class="s2">"; secure"</span><span class="p">;</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="nb">document</span><span class="p">.</span><span class="nx">cookie</span> <span class="o">=</span> <span class="nx">cookieText</span><span class="p">;</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'> <span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<a href="/blog/2013/08/03/cookieyu-session/" class="more-link">Read on →</a>
</div>
</article>
<article class="post" itemprop="blogPost" itemscope itemtype="http://schema.org/BlogPosting">
<div class="meta">
<div class="date">
<time datetime="2013-08-02T11:09:00+08:00" data-updated="true" itemprop="datePublished"></time></div>
<div class="tags">
<a class='category' href='/blog/categories/qian-duan/'>前端</a>
</div>
| <a href="/blog/2013/08/02/ajaxxiang-guan-zong-jie/#comments">Comments</a>
</div>
<h1 class="title" itemprop="name"><a href="/blog/2013/08/02/ajaxxiang-guan-zong-jie/" itemprop="url">Ajax相关总结</a></h1>
<div class="entry-content" itemprop="articleBody">
<h3>创建XMLHttpRequest对象</h3>
<p>创建XMLHttpRequest对象,跨浏览器兼容:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>