-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
459 lines (268 loc) · 20.1 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
<link rel="dns-prefetch" href="http://yoursite.com">
<title>Seven</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta property="og:type" content="website">
<meta property="og:title" content="Seven">
<meta property="og:url" content="http://yoursite.com/index.html">
<meta property="og:site_name" content="Seven">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Seven">
<link rel="alternative" href="/atom.xml" title="Seven" type="application/atom+xml">
<link rel="icon" href="img/favicon.ico">
<link rel="stylesheet" href="/main.css">
</head>
<body>
<div id="container">
<div class="left-col">
<div class="overlay"></div>
<div class="intrude-less">
<header id="header" class="inner">
<a href="/" class="profilepic">
<img src="img/avator.jpg" class="js-avatar">
</a>
<hgroup>
<h1 class="header-author"><a href="/">Seven c</a></h1>
</hgroup>
<nav class="header-menu">
<ul>
<li><a href="/">主页</a></li>
<li><a href="/tags/随笔">随笔</a></li>
</ul>
</nav>
<nav class="header-smart-menu">
<a class="js-smart-menu" data-idx="0" href="javascript:void(0)">所有文章</a>
<a class="js-smart-menu" data-idx="1" href="javascript:void(0)">标签</a>
<a class="js-smart-menu" data-idx="2" href="javascript:void(0)">友链</a>
<a class="js-smart-menu" data-idx="3" href="javascript:void(0)">关于我</a>
</nav>
<nav class="header-nav">
<div class="social">
<a class="github" target="_blank" href="#" title="github">github</a>
<a class="weibo" target="_blank" href="#" title="weibo">weibo</a>
<a class="rss" target="_blank" href="#" title="rss">rss</a>
<a class="zhihu" target="_blank" href="#" title="zhihu">zhihu</a>
</div>
</nav>
</header>
</div>
</div>
<div class="mid-col">
<nav id="mobile-nav">
<div class="overlay">
<div class="slider-trigger"><i class="icon-list"></i></div>
<h1 class="header-author js-mobile-header hide">Seven c</h1>
</div>
<div class="intrude-less">
<header id="header" class="inner">
<div class="profilepic">
<img src="img/avator.jpg" class="js-avatar">
</div>
<hgroup>
<h1 class="header-author">Seven c</h1>
</hgroup>
<nav class="header-menu">
<ul>
<li><a href="/">主页</a></li>
<li><a href="/tags/随笔">随笔</a></li>
</ul>
</nav>
<nav class="header-nav">
<div class="social">
<a class="github" target="_blank" href="#" title="github">github</a>
<a class="weibo" target="_blank" href="#" title="weibo">weibo</a>
<a class="rss" target="_blank" href="#" title="rss">rss</a>
<a class="zhihu" target="_blank" href="#" title="zhihu">zhihu</a>
</div>
</nav>
</header>
</div>
</nav>
<div class="body-wrap">
<article id="post-创建一个精准又具有矫正能力的倒计时" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/11/25/创建一个精准又具有矫正能力的倒计时/">创建一个精准又具有矫正能力的倒计时</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h3 id="倒计时如果既精确又可以避免各种bug"><a href="#倒计时如果既精确又可以避免各种bug" class="headerlink" title="倒计时如果既精确又可以避免各种bug"></a>倒计时如果既精确又可以避免各种bug</h3><p>本demo依赖moment库处理时间计算(时间计算不是本文章重点)</p>
<p>下面先简单介绍一下moment在本文章用的地方,如果有兴趣自行百度看文档</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">let</span> nowTime = <span class="keyword">new</span> <span class="built_in">Date</span>();<span class="comment">//获取当前时间</span></div><div class="line"><span class="keyword">let</span> targetTime = moment(nowTime).add(<span class="number">90</span>,<span class="string">'seconds'</span>);<span class="comment">//获取90秒后的时间</span></div><div class="line"><span class="built_in">console</span>.info(moment(targetTime).diff(moment(),<span class="string">'seconds'</span>));<span class="comment">//89</span></div></pre></td></tr></table></figure>
<p>下面开始正题</p>
<p>比如现在我们想要做一个获取验证码的按钮,下面给这个按钮写点击事件,在最早以前我写计时器都是这样写的</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">getCode</span>(<span class="params"></span>)</span>{</div><div class="line"> <span class="keyword">let</span> beginNum = <span class="number">90</span>;</div><div class="line"> <span class="keyword">let</span> showCount = <span class="literal">true</span>;<span class="comment">//用来判断是否显示点击获取验证码按钮</span></div><div class="line"> <span class="keyword">var</span> timer = setInterval(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>{</div><div class="line"> <span class="keyword">if</span>(beginNum <= <span class="number">0</span>){</div><div class="line"> showCount = <span class="literal">false</span>;</div><div class="line"> clearInterval(timer);</div><div class="line"> <span class="keyword">return</span>;</div><div class="line"> }</div><div class="line"> beginNum = beginNum - <span class="number">1</span>;</div><div class="line"> },<span class="number">1000</span>)</div><div class="line">}</div></pre></td></tr></table></figure>
<p>这样写会有很多很多问题,比如如果你的浏览器开启过多页面或者其他应用占内存太多,就会出现js的卡顿,当js卡顿时计算就会不精准,难以达到跟服务器的过期时间相匹配;还有在移动端的时候你会发现另一个有趣的bug,就是如果你点击获取验证码之后,后台这个程序,js会休眠,你过一个小时回到这个应用里面(假设没有被后台杀掉),你会发现计时器还停留在你后台这个app的时间,因为js休眠了,很尴尬的一个问题不是吗</p>
<p>后来经过启发,我做了另一版倒计时</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">getCode</span>(<span class="params"></span>)</span>{</div><div class="line"> <span class="keyword">let</span> beginNum;</div><div class="line"> <span class="keyword">let</span> showCount = <span class="literal">true</span>;</div><div class="line"> <span class="keyword">var</span> timer = setInterval(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>{</div><div class="line"> <span class="keyword">if</span>(beginNum <= <span class="number">0</span>){</div><div class="line"> showCount = <span class="literal">false</span>;</div><div class="line"> clearInterval(timer);</div><div class="line"> <span class="keyword">return</span>;</div><div class="line"> }</div><div class="line"> beginNum = moment(targetTime).diff(moment(),<span class="string">'seconds'</span>);</div><div class="line"> },<span class="number">1000</span>)</div><div class="line">}</div></pre></td></tr></table></figure>
<p>这个写法的好处就是,获取到了启动倒计时终点的时间,每隔一秒都会重新获取当前时间进行比对,获取差值,就算后台js被休眠了,当你回到这个应用,很快就会被矫正过来。</p>
</div>
<div class="article-info article-info-index">
<a href="/2016/11/25/创建一个精准又具有矫正能力的倒计时/" class="archive-article-date">
<time datetime="2016-11-25T11:17:12.000Z" itemprop="datePublished"><i class="icon-clock"></i>2016-11-25</time>
</a>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-es6-Destructuring" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/11/24/es6-Destructuring/">es6-Destructuring</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h3 id="es6解构赋值的一些解析"><a href="#es6解构赋值的一些解析" class="headerlink" title="es6解构赋值的一些解析"></a>es6解构赋值的一些解析</h3><p>es6正式推出已经有一段时间了,相信大家也看了很多的文档。这里有一些曾经困惑我的小疑问,我来解释一下。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> obj = {</div><div class="line"> <span class="attr">a</span>:<span class="number">215</span>,</div><div class="line"> <span class="attr">b</span>:<span class="number">34</span></div><div class="line">};</div><div class="line"><span class="keyword">var</span> {a,b} = obj;</div><div class="line"><span class="built_in">console</span>.info(a); <span class="comment">//215</span></div></pre></td></tr></table></figure>
<p>相信大家如果看过es6文档,对这个应该不陌生,那么这里有一个问题,解构出来的这个a是不是全局变量呢?来,我们继续往下看</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">let</span> a = <span class="number">1</span>;</div><div class="line"><span class="keyword">var</span> obj = {</div><div class="line"> <span class="attr">a</span>:<span class="number">215</span>,</div><div class="line"> <span class="attr">b</span>:<span class="number">34</span></div><div class="line">};</div><div class="line"><span class="keyword">var</span> {a,b} = obj;</div><div class="line"><span class="built_in">console</span>.info(a); <span class="comment">//215</span></div></pre></td></tr></table></figure>
<p>我一开始一直不太理解,这里面到底发生了什么事后来我发现</p>
<p><code>var {a,b} = obj</code>可以解释为这样<code>let a = obj.a;let b=obj.b</code>不难看出,a的值最终是被重新定义并赋值了</p>
</div>
<div class="article-info article-info-index">
<a href="/2016/11/24/es6-Destructuring/" class="archive-article-date">
<time datetime="2016-11-24T14:38:33.000Z" itemprop="datePublished"><i class="icon-clock"></i>2016-11-24</time>
</a>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-firstpage" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-inner">
<input type="hidden" class="isFancy" />
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/05/24/firstpage/">第一次搭建博客随便写写</a>
</h1>
</header>
<div class="article-entry" itemprop="articleBody">
<h3 id="第一次自己搭建博客"><a href="#第一次自己搭建博客" class="headerlink" title="第一次自己搭建博客"></a>第一次自己搭建博客</h3><p>一个经验不怎么丰富的前端,按照我们leader的对我的评价就是不求甚解。我也很承认这句话啊,,只是表面会用,但是并不懂其中原理,没有深层次的掌握理解。</p>
<p>一开始做这行主要是大学毕业后,对人生的迷茫,在大学舍友的带领下,走上了前端这一条不归路。老实讲,我以为随便干个三四年就能成为一个全栈工程师,后来发现我想多了。首先,前端这条路是走不到头的,或者说再怎么样经验丰富的前端也不会能够独当一面,前端转全栈的学习曲线过于陡峭;其次,随着这几年移动端的蓬勃发展,前端也越来越抢手,然而前端框架和新知识的更新速度更是日新月异,简直是像飞一样,,在我刚从事前端的那年,熟练掌握jqery就能叫做大神了,到处都抢着,,到现在你要是没有个mvc、mvvm 的框架的项目经验都很难找到工作了。几个月一个大版本,以前的东西全都推翻重来,着实看不到头。</p>
<p>人生还是要有自己的规划,当然了,除了富二代以外,其他跟我一样的普通人做程序员运气占百分之七十,剩下的三十看你的能力了。碰到一个好的团队,半年带你飞黄腾达也不是什么不能想的事。没有点儿拿的出手的本事,缺乏学习能力跟不上时代步伐的人也是走不远的。</p>
</div>
<div class="article-info article-info-index">
<a href="/2016/05/24/firstpage/" class="archive-article-date">
<time datetime="2016-05-24T14:14:27.000Z" itemprop="datePublished"><i class="icon-clock"></i>2016-05-24</time>
</a>
<div class="clearfix"></div>
</div>
</div>
</article>
</div>
<footer id="footer">
<div class="outer">
<div id="footer-info">
<div class="footer-left">
© 2016 Seven c
</div>
<div class="footer-right">
<a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/litten/hexo-theme-yilia" target="_blank">Yilia</a> by Litten
</div>
</div>
</div>
</footer>
</div>
<script>
var yiliaConfig = {
fancybox: true,
mathjax: false,
animate: true,
isHome: true,
isPost: false,
isArchive: false,
isTag: false,
isCategory: false,
open_in_new: true,
root: "/",
innerArchive: true
}
</script>
<script src="/./main.js"></script>
<div class="tools-col">
<ul class="btn-wrap">
<li class="chose" data-hook="tools-section-all"><span class="text">全部</span><i class="icon-book"></i></li>
<li data-hook="tools-section-tag"><span class="text">标签</span><i class="icon-price-tags"></i></li>
<li data-hook="tools-section-friends"><span class="text">友链</span><i class="icon-link"></i></li>
<li data-hook="tools-section-me"><span class="text">我</span><i class="icon-smile"></i></li>
</ul>
<div class="tools-wrap">
<section class="tools-section tools-section-all chose">
</section>
<section class="tools-section tools-section-tag">
<div class="widget tagcloud" id="js-tagcloud">
</div>
</section>
<section class="tools-section tools-section-friends">
<div class="friends-wrap" id="js-friends">
<a target="_blank" class="main-nav-link switch-friends-link" href="http://localhost:4000/">友情链接1</a>
<a target="_blank" class="main-nav-link switch-friends-link" href="http://localhost:4000/">友情链接2</a>
<a target="_blank" class="main-nav-link switch-friends-link" href="http://localhost:4000/">友情链接3</a>
<a target="_blank" class="main-nav-link switch-friends-link" href="http://localhost:4000/">友情链接4</a>
<a target="_blank" class="main-nav-link switch-friends-link" href="http://localhost:4000/">友情链接5</a>
<a target="_blank" class="main-nav-link switch-friends-link" href="http://localhost:4000/">友情链接6</a>
</div>
</section>
<section class="tools-section tools-section-me">
<div class="aboutme-wrap" id="js-aboutme">北漂小前端</div>
</section>
</div>
</div>
<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
<!-- Background of PhotoSwipe.
It's a separate element as animating opacity is faster than rgba(). -->
<div class="pswp__bg"></div>
<!-- Slides wrapper with overflow:hidden. -->
<div class="pswp__scroll-wrap">
<!-- Container that holds slides.
PhotoSwipe keeps only 3 of them in the DOM to save memory.
Don't modify these 3 pswp__item elements, data is added later on. -->
<div class="pswp__container">
<div class="pswp__item"></div>
<div class="pswp__item"></div>
<div class="pswp__item"></div>
</div>
<!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
<div class="pswp__ui pswp__ui--hidden">
<div class="pswp__top-bar">
<!-- Controls are self-explanatory. Order can be changed. -->
<div class="pswp__counter"></div>
<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
<button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>
<button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
<button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
<!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
<!-- element will get class pswp__preloader--active when preloader is running -->
<div class="pswp__preloader">
<div class="pswp__preloader__icn">
<div class="pswp__preloader__cut">
<div class="pswp__preloader__donut"></div>
</div>
</div>
</div>
</div>
<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
<div class="pswp__share-tooltip"></div>
</div>
<button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
</button>
<button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
</button>
<div class="pswp__caption">
<div class="pswp__caption__center"></div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>