-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
726 lines (503 loc) · 29.3 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
<link rel="mask-icon" href="/images/logo.svg" color="#222">
<link rel="stylesheet" href="/css/main.css">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
<script id="hexo-configurations">
var NexT = window.NexT || {};
var CONFIG = {
hostname: new URL('https://sishuguojixuefu.github.io').hostname,
root: '/',
scheme: 'Mist',
version: '7.6.0',
exturl: false,
sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
copycode: {"enable":false,"show_result":false,"style":null},
back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
bookmark: {"enable":true,"color":"#222","save":"auto"},
fancybox: false,
mediumzoom: false,
lazyload: true,
pangu: false,
comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
algolia: {
appID: '',
apiKey: '',
indexName: '',
hits: {"per_page":10},
labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
},
localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
path: 'search.xml',
motion: {"enable":true,"async":true,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
};
</script>
<meta property="og:type" content="website">
<meta property="og:title" content="晞格玛云·技术博客">
<meta property="og:url" content="https://sishuguojixuefu.github.io/index.html">
<meta property="og:site_name" content="晞格玛云·技术博客">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="晞格玛云·技术团队">
<meta name="twitter:card" content="summary">
<link rel="canonical" href="https://sishuguojixuefu.github.io/">
<script id="page-configurations">
// https://hexo.io/docs/variables.html
CONFIG.page = {
sidebar: "",
isHome: true,
isPost: false
};
</script>
<title>晞格玛云·技术博客</title>
<noscript>
<style>
.use-motion .brand,
.use-motion .menu-item,
.sidebar-inner,
.use-motion .post-block,
.use-motion .pagination,
.use-motion .comments,
.use-motion .post-header,
.use-motion .post-body,
.use-motion .collection-header { opacity: initial; }
.use-motion .site-title,
.use-motion .site-subtitle {
opacity: initial;
top: initial;
}
.use-motion .logo-line-before i { left: initial; }
.use-motion .logo-line-after i { right: initial; }
</style>
</noscript>
</head>
<body itemscope itemtype="http://schema.org/WebPage">
<div class="container use-motion">
<div class="headband"></div>
<header class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-container">
<div class="site-meta">
<div>
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<span class="site-title">晞格玛云·技术博客</span>
<span class="logo-line-after"><i></i></span>
</a>
</div>
<p class="site-subtitle">敢想能拼,拿结果。说到做到,有沉淀。</p>
</div>
<div class="site-nav-toggle">
<div class="toggle" aria-label="切换导航栏">
<span class="toggle-line toggle-line-first"></span>
<span class="toggle-line toggle-line-middle"></span>
<span class="toggle-line toggle-line-last"></span>
</div>
</div>
</div>
<nav class="site-nav">
<ul id="menu" class="menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>
</li>
<li class="menu-item menu-item-tags">
<a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>
</li>
<li class="menu-item menu-item-categories">
<a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>
</li>
<li class="menu-item menu-item-search">
<a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
</a>
</li>
</ul>
</nav>
<div class="site-search">
<div class="popup search-popup">
<div class="search-header">
<span class="search-icon">
<i class="fa fa-search"></i>
</span>
<div class="search-input-container">
<input autocomplete="off" autocorrect="off" autocapitalize="none"
placeholder="搜索..." spellcheck="false"
type="text" id="search-input">
</div>
<span class="popup-btn-close">
<i class="fa fa-times-circle"></i>
</span>
</div>
<div id="search-result"></div>
</div>
<div class="search-pop-overlay"></div>
</div>
</div>
</header>
<div class="back-to-top">
<i class="fa fa-arrow-up"></i>
<span>0%</span>
</div>
<div class="reading-progress-bar"></div>
<a role="button" class="book-mark-link book-mark-link-fixed"></a>
<main class="main">
<div class="main-inner">
<div class="content-wrap">
<div class="content">
<div class="posts-expand">
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-CN">
<link itemprop="mainEntityOfPage" href="https://sishuguojixuefu.github.io/4999/12/31/hello-world/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.jpg">
<meta itemprop="name" content="晞格玛云·技术团队">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="晞格玛云·技术博客">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/4999/12/31/hello-world/" class="post-title-link" itemprop="url">Hexo博客使用说明</a>
</h1>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建时间:5000-01-01 00:00:00" itemprop="dateCreated datePublished" datetime="5000-01-01T00:00:00+08:00">5000-01-01</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">Valine:</span>
<a title="valine" href="/4999/12/31/hello-world/#comments" itemprop="discussionUrl">
<span class="post-comments-count valine-comment-count" data-xid="/4999/12/31/hello-world/" itemprop="commentCount"></span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>基于Hexo搭建的技术博客平台,相较于旧平台,主要有以下特性和改进:</p>
<ul>
<li>使用Git项目形式管理博客,将md文件提交到服务器即可自动部署</li>
<li>支持本地预览</li>
<li>支持缓存阅读进度</li>
<li>支持分页</li>
<li>支持使用分类和标签对文章进行归类</li>
<li>无后台的搜索功能</li>
<li>无后台的评论系统</li>
<li>支持引用本地图片避免外链</li>
<li>支持引入<code>codepen</code>、<code>codesandbox</code>、<code>jsfiddle</code>等在线代码</li>
<li>访客统计等更多丰富的插件和扩展能力</li>
</ul>
<h3 id="☯-最简单直接的写文章方式"><a href="#☯-最简单直接的写文章方式" class="headerlink" title="☯. 最简单直接的写文章方式"></a>☯. 最简单直接的写文章方式</h3><p>无需下载项目到本地,直接打开github项目地址:</p>
<p><a href="https://github.com/sishuguojixuefu/blog/new/master/source/_posts" target="_blank" rel="noopener">https://github.com/sishuguojixuefu/blog/new/master/source/_posts</a></p>
<p>创建md文件并保存,完毕。</p>
<p>注意在md文件头部添加必要的<a href="https://hexo.io/zh-cn/docs/front-matter" target="_blank" rel="noopener"><code>front-matter</code></a>信息<br>,例如:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: Hexo博客使用说明</span><br><span class="line">date: 2020-01-08 18:53:59</span><br><span class="line">---</span><br></pre></td></tr></table></figure>
<p>站点会在push后自动部署,等待一段时间刷新网页即可。</p>
<h3 id="1-下载项目到本地,安装依赖"><a href="#1-下载项目到本地,安装依赖" class="headerlink" title="1. 下载项目到本地,安装依赖"></a>1. 下载项目到本地,安装依赖</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://github.com/sishuguojixuefu/blog.git blog</span><br><span class="line">yarn install</span><br></pre></td></tr></table></figure>
<h3 id="2-编写新文章"><a href="#2-编写新文章" class="headerlink" title="2. 编写新文章"></a>2. 编写新文章</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo new <span class="string">"文章标题"</span></span><br></pre></td></tr></table></figure>
<p>通过命令创建文章,会自动根据<code>scaffolds</code>目录下的模板新建md文件。</p>
<p>文件开头的<a href="https://hexo.io/zh-cn/docs/front-matter" target="_blank" rel="noopener"><code>front-matter</code></a>默认包含了一些动态生成的信息,比如文章的标题和时间。</p>
<h3 id="3-调试和预览"><a href="#3-调试和预览" class="headerlink" title="3. 调试和预览"></a>3. 调试和预览</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure>
<p>启动后访问<code>http://localhost:4000</code>即可本地预览</p>
<h3 id="4-常用功能"><a href="#4-常用功能" class="headerlink" title="4. 常用功能"></a>4. 常用功能</h3><h4 id="分类与标签"><a href="#分类与标签" class="headerlink" title="分类与标签"></a>分类与标签</h4><p>在<a href="https://hexo.io/zh-cn/docs/front-matter" target="_blank" rel="noopener"><code>front-matter</code></a>中填写,比如</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: 这是一个标题</span><br><span class="line">date: 2020-01-08 22:52:13</span><br><span class="line">categories:</span><br><span class="line"> - [前端, 移动端]</span><br><span class="line"> - [前端, PC端]</span><br><span class="line"> - [算法]</span><br><span class="line">tags:</span><br><span class="line"> - Vue</span><br><span class="line"> - React</span><br><span class="line"> - 递归</span><br><span class="line"> - 算法</span><br><span class="line">---</span><br></pre></td></tr></table></figure>
<p>注意分类<code>category</code>和标签<code>tag</code>的区别,后者类似关键字。</p>
<p>详情参考:<a href="https://hexo.io/zh-cn/docs/front-matter" target="_blank" rel="noopener">https://hexo.io/zh-cn/docs/front-matter</a></p>
<h4 id="插入本地图片"><a href="#插入本地图片" class="headerlink" title="插入本地图片"></a>插入本地图片</h4><p>在<code>source/_posts</code>目录下创建与当前文章同名的文件夹,在其中放入图片等附件。</p>
<p>然后在md文档中插入以下代码即可显示存放在站点的本地图片。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">{% asset_img 1.png %}</span><br></pre></td></tr></table></figure>
<p>详情参考:<a href="https://hexo.io/zh-cn/docs/asset-folders" target="_blank" rel="noopener">https://hexo.io/zh-cn/docs/asset-folders</a></p>
<h4 id="插入codepen在线代码"><a href="#插入codepen在线代码" class="headerlink" title="插入codepen在线代码"></a>插入codepen在线代码</h4><p>参考<a href="https://github.com/bibixx/hexo-tag-codepen#usage" target="_blank" rel="noopener">https://github.com/bibixx/hexo-tag-codepen#usage</a></p>
<h3 id="进阶使用"><a href="#进阶使用" class="headerlink" title="进阶使用"></a>进阶使用</h3><p>更多高级应用请查看<a href="https://hexo.io/zh-cn/docs/writing" target="_blank" rel="noopener">Hexo中文文档</a></p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-CN">
<link itemprop="mainEntityOfPage" href="https://sishuguojixuefu.github.io/2020/01/08/%E8%AE%A9IDE%E8%AF%86%E5%88%ABwebpack%E7%9A%84%E5%88%AB%E5%90%8Dalias/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.jpg">
<meta itemprop="name" content="晞格玛云·技术团队">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="晞格玛云·技术博客">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/2020/01/08/%E8%AE%A9IDE%E8%AF%86%E5%88%ABwebpack%E7%9A%84%E5%88%AB%E5%90%8Dalias/" class="post-title-link" itemprop="url">让IDE识别vue-cli3中webpack的别名alias</a>
</h1>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建时间:2020-01-08 22:53:59" itemprop="dateCreated datePublished" datetime="2020-01-08T22:53:59+08:00">2020-01-08</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/%E5%89%8D%E7%AB%AF/" itemprop="url" rel="index">
<span itemprop="name">前端</span>
</a>
</span>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">Valine:</span>
<a title="valine" href="/2020/01/08/%E8%AE%A9IDE%E8%AF%86%E5%88%ABwebpack%E7%9A%84%E5%88%AB%E5%90%8Dalias/#comments" itemprop="discussionUrl">
<span class="post-comments-count valine-comment-count" data-xid="/2020/01/08/%E8%AE%A9IDE%E8%AF%86%E5%88%ABwebpack%E7%9A%84%E5%88%AB%E5%90%8Dalias/" itemprop="commentCount"></span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<blockquote>
<p>本文由杭州前端团队齐霁分享</p>
</blockquote>
<p>许多项目脚手架默认就会把src目录添加一个<code>@</code>别名,项目中实际引入时,虽然可以精简路径,但也带来一个很麻烦的问题:<br>IDE无法识别这些别名,因此导致无法自动完成路径、无法识别引用资源的输出、出现不必要的告警等情况。</p>
<p>偶然发现vscode的web项目里有一个<code>jsconfig.json</code>文件,如:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">{</span><br><span class="line"> <span class="attr">"compilerOptions"</span>: {</span><br><span class="line"> <span class="attr">"baseUrl"</span>: <span class="string">"."</span>,</span><br><span class="line"> <span class="attr">"paths"</span>: {</span><br><span class="line"> <span class="attr">"@/*"</span>: [<span class="string">"src/*"</span>]</span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"target"</span>: <span class="string">"ES6"</span>,</span><br><span class="line"> <span class="attr">"module"</span>: <span class="string">"commonjs"</span>,</span><br><span class="line"> <span class="attr">"allowSyntheticDefaultImports"</span>: <span class="literal">true</span></span><br><span class="line"> },</span><br><span class="line"> <span class="attr">"include"</span>: [<span class="string">"src/**/*"</span>],</span><br><span class="line"> <span class="attr">"exclude"</span>: [<span class="string">"node_modules"</span>]</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>只要有这个文件,vscode就可以正常识别出别名了。</p>
<p>后来发现JetBrains家的IDE更简单,配置指定一下就行:</p>
<img data-src="/2020/01/08/%E8%AE%A9IDE%E8%AF%86%E5%88%ABwebpack%E7%9A%84%E5%88%AB%E5%90%8Dalias/1.png" class="">
<p>在项目设置的webpack标签页里,将配置文件指向<code><projectRoot>/node_modules/@vue/cli-service/webpack.config.js</code>即可。</p>
<p>保存并重新打开项目以后,不只<code>src</code>,所有的别名比如<code>utils</code>等等都可以被正常识别。</p>
<p>其实这都已经写在<code>vue-cli3</code>的<a href="https://cli.vuejs.org/zh/guide/webpack.html#以一个文件的方式使用解析好的配置" target="_blank" rel="noopener">文档</a>里了,只是原始表述不太直观,被我一直忽略了。</p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-CN">
<link itemprop="mainEntityOfPage" href="https://sishuguojixuefu.github.io/2020/01/08/CSS3%E5%AE%9E%E7%8E%B0%E8%BD%AC%E7%9B%98%E6%8A%BD%E5%A5%96/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.jpg">
<meta itemprop="name" content="晞格玛云·技术团队">
<meta itemprop="description" content="">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="晞格玛云·技术博客">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/2020/01/08/CSS3%E5%AE%9E%E7%8E%B0%E8%BD%AC%E7%9B%98%E6%8A%BD%E5%A5%96/" class="post-title-link" itemprop="url">CSS3实现转盘抽奖</a>
</h1>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建时间:2020-01-08 22:52:13" itemprop="dateCreated datePublished" datetime="2020-01-08T22:52:13+08:00">2020-01-08</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/%E5%89%8D%E7%AB%AF/" itemprop="url" rel="index">
<span itemprop="name">前端</span>
</a>
</span>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">Valine:</span>
<a title="valine" href="/2020/01/08/CSS3%E5%AE%9E%E7%8E%B0%E8%BD%AC%E7%9B%98%E6%8A%BD%E5%A5%96/#comments" itemprop="discussionUrl">
<span class="post-comments-count valine-comment-count" data-xid="/2020/01/08/CSS3%E5%AE%9E%E7%8E%B0%E8%BD%AC%E7%9B%98%E6%8A%BD%E5%A5%96/" itemprop="commentCount"></span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<blockquote>
<p>本文由杭州前端团队齐霁分享</p>
</blockquote>
<p>想实现一个转盘抽奖的需求,搜了一下现有的轮子,有的是用jQuery的动画函数实现的,有的是用canvas绘图然后再用高频率的setTimeout调用旋转方法,前者太老了没法简单移植到vue项目,后者感觉性能表现可能不会太好。也有一些用CSS动画的方案,设计了加速-匀速-减速三个动画,再计算偏转角度让三个动画尽可能无缝衔接,但我感觉绕了大远路,应该有更简单轻量的实现方案。个人更倾向于用transition来实现,不过网上的例子感觉还不够好,有的倾斜文字都没有对齐,最后还是自己手写了一个。核心思路是用transition以及rotate实现旋转动画,使用transition-origin和rotate绘制出定位较为精确的轮盘奖项,同时支持动态设置奖品数量。</p>
<iframe id="cp_embed_XLgBQP" src="//codepen.io/mirari/embed/XLgBQP?height=600&theme-id=dark&slug-hash=XLgBQP&default-tab=js,result&embed-version=2" scrolling="no" frameborder="no" height="600" allowTransparency="true" allowfullscreen="true" class="cp_embed_iframe" style="width: 100%; overflow: hidden;"></iframe>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
</div>
</div>
<script>
window.addEventListener('tabs:register', () => {
let activeClass = CONFIG.comments.activeClass;
if (CONFIG.comments.storage) {
activeClass = localStorage.getItem('comments_active') || activeClass;
}
if (activeClass) {
let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
if (activeTab) {
activeTab.click();
}
}
});
if (CONFIG.comments.storage) {
window.addEventListener('tabs:click', event => {
if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
let commentClass = event.target.classList[1];
localStorage.setItem('comments_active', commentClass);
});
}
</script>
</div>
<div class="toggle sidebar-toggle">
<span class="toggle-line toggle-line-first"></span>
<span class="toggle-line toggle-line-middle"></span>
<span class="toggle-line toggle-line-last"></span>
</div>
<aside class="sidebar">
<div class="sidebar-inner">
<ul class="sidebar-nav motion-element">
<li class="sidebar-nav-toc">
文章目录
</li>
<li class="sidebar-nav-overview">
站点概览
</li>
</ul>
<!--noindex-->
<div class="post-toc-wrap sidebar-panel">
</div>
<!--/noindex-->
<div class="site-overview-wrap sidebar-panel">
<div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
<img class="site-author-image" itemprop="image" alt="晞格玛云·技术团队"
src="/images/avatar.jpg">
<p class="site-author-name" itemprop="name">晞格玛云·技术团队</p>
<div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
<nav class="site-state">
<div class="site-state-item site-state-posts">
<a href="/archives/">
<span class="site-state-item-count">3</span>
<span class="site-state-item-name">日志</span>
</a>
</div>
<div class="site-state-item site-state-categories">
<a href="/categories/">
<span class="site-state-item-count">1</span>
<span class="site-state-item-name">分类</span></a>
</div>
<div class="site-state-item site-state-tags">
<a href="/tags/">
<span class="site-state-item-count">6</span>
<span class="site-state-item-name">标签</span></a>
</div>
</nav>
</div>
<div class="links-of-author motion-element">
<span class="links-of-author-item">
<a href="https://github.com/sishuguojixuefu" title="GitHub → https://github.com/sishuguojixuefu" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
</span>
<span class="links-of-author-item">
<a href="https://www.zhipin.com/gongsir/f6ce940fa563effe0HB60ty8.html" title="加入我们 → https://www.zhipin.com/gongsir/f6ce940fa563effe0HB60ty8.html" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>加入我们</a>
</span>
</div>
</div>
</div>
</aside>
<div id="sidebar-dimmer"></div>
</div>
</main>
<footer class="footer">
<div class="footer-inner">
<div class="copyright">
©
<span itemprop="copyrightYear">2020</span>
<span class="with-love">
<i class="fa fa-heart"></i>
</span>
<span class="author" itemprop="copyrightHolder">晞格玛云·技术团队</span>
</div>
<div class="busuanzi-count">
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
<span class="post-meta-item-icon">
<i class="fa fa-user"></i>
</span>
<span class="site-uv" title="总访客量">
<span id="busuanzi_value_site_uv"></span>
</span>
</span>
<span class="post-meta-divider">|</span>
<span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
<span class="post-meta-item-icon">
<i class="fa fa-eye"></i>
</span>
<span class="site-pv" title="总访问量">
<span id="busuanzi_value_site_pv"></span>
</span>
</span>
</div>
</div>
</footer>
</div>
<script size="90" alpha="0.6" zIndex="-1" src="/lib/canvas-ribbon/canvas-ribbon.js"></script>
<script src="/lib/anime.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>
<script src="/lib/velocity/velocity.min.js"></script>
<script src="/lib/velocity/velocity.ui.min.js"></script>
<script src="/js/utils.js"></script>
<script src="/js/motion.js"></script>
<script src="/js/schemes/muse.js"></script>
<script src="/js/next-boot.js"></script>
<script src="/js/bookmark.js"></script>
<script src="/js/local-search.js"></script>
<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
var GUEST = ['nick', 'mail', 'link'];
var guest = 'nick,mail,link';
guest = guest.split(',').filter(item => {
return GUEST.includes(item);
});
new Valine({
el: '#valine-comments',
verify: false,
notify: false,
appId: 'auTjMQhOlwI95tx3I51MhweY-gzGzoHsz',
appKey: '3Vu205S6Dm62nEAp05P8S46E',
placeholder: "Just go go",
avatar: 'mm',
meta: guest,
pageSize: '10' || 10,
visitor: false,
lang: '' || 'zh-cn',
path: location.pathname,
recordIP: false,
serverURLs: ''
});
}, window.Valine);
});
</script>
</body>
</html>