DIYsay
日志7
标签15
分类2

优雅的将valine增加博主标识并美化样式

valine增加博主、小伙伴、游客标签,美化样式、增加背景图、自定义表情…
valine1

valine的使用

valine官方文档:valine.js.org
Valine 虽然自称是无后台实现的评论系统,但其实也是基于云数据库 LeanCloud 实现的评论存储,所以你得在LeanCloud创建一个应用,获取appidappkey
请使用 //cdn.jsdelivr.net/gh/HCLonely/Valine@latest/dist/Valine.min.js 其他版本可用性未知。

输入界面增加背景图

valine2
图片是:drew叔的,使用方法,将以下代码增加到你对应的CSS中:

1
2
3
4
5
6
7
8
#veditor {
background-image: url(https://cdn.jsdelivr.net/gh/DIYsay/Blog_CDN_2/imgs/diysay-valine.webp);
background-size: contain;
background-repeat: no-repeat;
background-position: right;
background-color: rgba(255, 255, 255, 0);
resize: vertical
}

上面url参数中的链接可以换成自己喜欢的图片。如果内容过长,图片会挡住部分内容,所以我们要它应该失焦的时候显示,聚焦的时候消失,CSS代码如下:

1
2
3
4
#veditor:focus{
background-position-y: 200px;
transition: all 0.2s ease-in-out 0s;
}

上面参数中,200px代表图片高度,0.2s代表消失时间。

头像旋转

把鼠标放在头像上的时候让头像转起来,css代码如下:

1
2
3
4
5
6
7
8
9
10
11
img.vimg {
transition: all 1s /* 旋转时间为 1s */
}

img.vimg:hover {
transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-o-transform: rotate(360deg);
-ms-transform: rotate(360deg);
}

评论卡片式背景

就是每楼(回帖算同楼)的评论是一个卡片,几楼就是几个卡片了,我主题用了太丑,所以我就没用了,css如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#vcomments .vcards .vcard {
padding: 15px 20px 0 20px;
border-radius: 10px;
margin-bottom: 15px;
box-shadow: 0 0 4px 1px rgba(0, 0, 0, .12);
transition: all .3s
}

#vcomments .vcards .vcard:hover {
box-shadow: 0 0 8px 3px rgba(0, 0, 0, .12)
}

#vcomments .vcards .vcard .vh .vcard {
border: none;
box-shadow: none;
}

增加博主等标识以及浏览器图标

请务必使用文头的js,用低版的js不行。
请参考以下字段:

1
2
3
4
5
6
7
8
9
10
11
12
new Valine({
el: '#vcomments',
appId: '',
appKey: '',
master: '48c8f1e79dd340e4b247820fee013082', //博主邮箱md5
tagMeta: ["博主","小伙伴","访客"], //标识字段名
friends: ["fe01ce2a7fbac8fafaed7c982a04e229","fe01ce2a7fbac8fafaed7c982a04e229"], //小伙伴邮箱Md5
metaPlaceholder: {"nick":"昵称/QQ号","mail":"邮箱"},
placeholder: "填写邮箱可以及时收到回复哦(●'◡'●)",
avatar: 'wavatar',
enableQQ: true,
});

值得一提的是:
master:博主的邮箱
tagMeta:字段名(这是自定义的,你未必要自称博主)
friends小伙伴的邮箱
只要增加以上字段,即可实现其功能,博主、小伙伴标识的出现是根据邮箱判断的,只要你邮箱填写的是对应的,就出现对应图标。
上述参数用md5加密,推荐使用网站:md5jiami.51240.com 在线生成。

自定义表情

这个官方文档说的很明白了,给个例子你应该就秒懂了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
new Valine({
el:'#vcomment',
appId:'<Your_APP_ID>',
appKey:'<Your_APP_KEY>',

// 这里设置CDN, 默认微博表情CDN
emojiCDN: 'https://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/',
// 表情title和图片映射
emojiMaps: {
"smile":"e3/2018new_weixioa02_org.png",
"lovely":"09/2018new_keai_org.png",
// ... 更多表情
}
})

评论框css样式

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
.v[data-class=v] {
font-size:16px;
text-align:left
}
.v[data-class=v] * {
-webkit-box-sizing:border-box;
box-sizing:border-box;
line-height:1.75
}
.v[data-class=v] .status-bar,.v[data-class=v] .veditor,.v[data-class=v] .vinput,.v[data-class=v] p,.v[data-class=v] pre code {
color:#555
}
.v[data-class=v] .vsys,.v[data-class=v] .vtime {
color:#b3b3b3
}
.v[data-class=v] .text-right {
text-align:right
}
.v[data-class=v] .text-center {
text-align:center
}
.v[data-class=v] img {
max-width:100%;
border:none
}
.v[data-class=v] hr {
margin:.825em 0;
border-color:#f6f6f6;
border-style:dashed
}
.v[data-class=v].hide-avatar .vimg {
display:none
}
.v[data-class=v] a {
position:relative;
cursor:pointer;
color:#1abc9c;
text-decoration:none;
display:inline-block
}
.v[data-class=v] a:hover {
color:#d7191a
}
.v[data-class=v] code,.v[data-class=v] pre {
background-color:#f8f8f8;
padding:.2em .4em;
border-radius:3px;
font-size:85%;
margin:0
}
.v[data-class=v] pre {
padding:10px;
overflow:auto;
line-height:1.45
}
.v[data-class=v] pre code {
padding:0;
background:transparent;
white-space:pre-wrap;
word-break:keep-all
}
.v[data-class=v] blockquote {
color:#666;
margin:.5em 0;
padding:0 0 0 1em;
border-left:8px solid hsla(0,0%,93%,.5)
}
.v[data-class=v] .vinput {
border:none;
resize:none;
outline:none;
padding:10px 5px;
max-width:100%;
font-size:.775em
}
.v[data-class=v] input[type=checkbox],.v[data-class=v] input[type=radio] {
display:inline-block;
vertical-align:middle;
margin-top:-2px
}
.v[data-class=v] .vicon {
cursor:pointer;
display:inline-block;
overflow:hidden;
fill:#555;
vertical-align:middle
}
.v[data-class=v] .vicon+.vicon {
margin-left:10px
}
.v[data-class=v] .vicon.actived {
fill:#66b1ff
}
.v[data-class=v] .vrow {
font-size:0;
padding:10px 0
}
.v[data-class=v] .vrow .vcol {
display:inline-block;
vertical-align:middle;
font-size:14px
}
.v[data-class=v] .vrow .vcol.vcol-20 {
width:20%
}
.v[data-class=v] .vrow .vcol.vcol-30 {
width:30%
}
.v[data-class=v] .vrow .vcol.vcol-40 {
width:40%
}
.v[data-class=v] .vrow .vcol.vcol-50 {
width:50%
}
.v[data-class=v] .vrow .vcol.vcol-60 {
width:60%
}
.v[data-class=v] .vrow .vcol.vcol-70 {
width:70%
}
.v[data-class=v] .vrow .vcol.vcol-80 {
width:80%
}
.v[data-class=v] .vrow .vcol.vctrl {
font-size:12px
}
.v[data-class=v] .emoji,.v[data-class=v] .vemoji {
max-width:25px;
vertical-align:middle;
margin:0 1px;
display:inline-block
}
.v[data-class=v] .vwrap {
border:1px solid #f0f0f0;
border-radius:4px;
margin-bottom:10px;
overflow:hidden;
position:relative;
padding:10px
}
.v[data-class=v] .vwrap input {
background:transparent
}
.v[data-class=v] .vwrap .vedit {
position:relative;
padding-top:10px
}
.v[data-class=v] .vwrap .cancel-reply-btn {
position:absolute;
right:5px;
top:5px;
cursor:pointer
}
.v[data-class=v] .vwrap .vemojis {
display:none;
font-size:18px;
max-height:145px;
overflow:auto;
padding-bottom:10px;
-webkit-box-shadow:0 0 1px #f0f0f0;
box-shadow:0 0 1px #f0f0f0
}
.v[data-class=v] .vwrap .vemojis i {
font-style:normal;
padding-top:7px;
width:36px;
cursor:pointer;
text-align:center;
display:inline-block;
vertical-align:middle
}
.v[data-class=v] .vwrap .vpreview {
padding:7px;
-webkit-box-shadow:0 0 1px #f0f0f0;
box-shadow:0 0 1px #f0f0f0
}
.v[data-class=v] .vwrap .vheader .vinput {
width:33.33%;
border-bottom:1px dashed #dedede
}
.v[data-class=v] .vwrap .vheader.item2 .vinput {
width:50%
}
.v[data-class=v] .vwrap .vheader.item1 .vinput {
width:100%
}
.v[data-class=v] .vwrap .vheader .vinput:focus {
border-bottom-color:#eb5055
}
@media screen and (max-width:520px) {
.v[data-class=v] .vwrap .vheader.item2 .vinput,.v[data-class=v] .vwrap .vheader .vinput {
width:100%
}
}.v[data-class=v] .vpower {
color:#999;
font-size:.75em;
padding:.5em 0
}
.v[data-class=v] .vpower a {
font-size:.75em
}
.v[data-class=v] .vcount {
padding:5px;
font-weight:600;
font-size:1.25em
}
.v[data-class=v] ol,.v[data-class=v] ul {
padding:0;
margin-left:1.25em
}
.v[data-class=v] .txt-center {
text-align:center
}
.v[data-class=v] .txt-right {
text-align:right
}
.v[data-class=v] .pd5 {
padding:5px
}
.v[data-class=v] .pd10 {
padding:10px
}
.v[data-class=v] .veditor {
width:100%;
min-height:8.75em;
font-size:.875em;
background:transparent;
resize:vertical;
-webkit-transition:all .25s ease;
transition:all .25s ease
}
.v[data-class=v] .vbtn {
-webkit-transition-duration:.4s;
transition-duration:.4s;
text-align:center;
color:#555;
border:1px solid #ededed;
border-radius:.3em;
display:inline-block;
background:transparent;
margin-bottom:0;
font-weight:400;
vertical-align:middle;
-ms-touch-action:manipulation;
touch-action:manipulation;
cursor:pointer;
white-space:nowrap;
padding:.5em 1.25em;
font-size:.875em;
line-height:1.42857143;
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
outline:none
}
.v[data-class=v] .vbtn+.vbtn {
margin-left:1.25em
}
.v[data-class=v] .vbtn:active,.v[data-class=v] .vbtn:hover {
color:#3090e4;
border-color:#3090e4
}
.v[data-class=v] .vbtn:disabled {
border-color:#e1e1e1;
color:#e1e1e1;
background-color:#fdfafa;
cursor:not-allowed
}
.v[data-class=v] .vempty {
padding:1.25em;
text-align:center;
color:#555;
overflow:auto
}
.v[data-class=v] .vsys {
display:inline-block;
padding:.2em .5em;
font-size:.75em;
border-radius:.2em;
margin-right:.3em
}
@media screen and (max-width:520px) {
.v[data-class=v] .vsys {
display:none
}
}.v[data-class=v] .vcards {
width:100%
}
.v[data-class=v] .vcards .vcard {
padding-top:1.25em;
position:relative;
display:block
}
.v[data-class=v] .vcards .vcard:after {
content:"";
clear:both;
display:block
}
.v[data-class=v] .vcards .vcard .vimg {
width:3.125em;
height:3.125em;
float:left;
border-radius:50%;
margin-right:.7525em;
border:1px solid #f5f5f5;
padding:.125em
}
@media screen and (max-width:720px) {
.v[data-class=v] .vcards .vcard .vimg {
width:2.5em;
height:2.5em
}
}.v[data-class=v] .vcards .vcard .vhead {
line-height:1.5;
margin-top:0
}
.v[data-class=v] .vcards .vcard .vhead .vnick {
position:relative;
font-size:.875em;
font-weight:500;
margin-right:.4em;
cursor:pointer;
text-decoration:none;
display:inline-block
}
.vtag {
font-size:12px;
display:inline-block;
line-height:20px;
border-radius:2px;
color:#fff;
padding:0 5px;
position:inherit;
}
.vtag.vmaster {
background:#ffa51e
}
.vtag.vfriend {
background:#6cf
}
.vtag.vvisitor {
background:#828282
}
.v[data-class=v] .vcards .vcard .vhead .vnick:hover {
color:#d7191a
}
.v[data-class=v] .vcards .vcard .vh {
overflow:hidden;
padding-bottom:.5em;
border-bottom:1px dashed #f5f5f5
}
.v[data-class=v] .vcards .vcard .vh .vtime {
font-size:.75em;
margin-right:.875em
}
.v[data-class=v] .vcards .vcard .vh .vmeta {
line-height:1;
position:relative
}
.v[data-class=v] .vcards .vcard .vh .vmeta .vat {
font-size:.8125em;
color:#ef2f11;
cursor:pointer;
float:right
}
.v[data-class=v] .vcards .vcard:last-child .vh {
border-bottom:none
}
.v[data-class=v] .vcards .vcard .vcontent {
word-wrap:break-word;
word-break:break-all;
font-size:.875em;
line-height:2;
position:relative;
margin-bottom:.75em;
padding-top:.625em
}
.v[data-class=v] .vcards .vcard .vcontent.expand {
cursor:pointer;
max-height:8em;
overflow:hidden
}
.v[data-class=v] .vcards .vcard .vcontent.expand:before {
display:block;
content:"";
position:absolute;
width:100%;
left:0;
top:0;
bottom:3.15em;
background:-webkit-gradient(linear,left top,left bottom,from(hsla(0,0%,100%,0)),to(hsla(0,0%,100%,.9)));
background:linear-gradient(180deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.9));
z-index:999
}
.v[data-class=v] .vcards .vcard .vcontent.expand:after {
display:block;
content:attr(data-expand);
text-align:center;
color:#828586;
position:absolute;
width:100%;
height:3.15em;
line-height:3.15em;
left:0;
bottom:0;
z-index:999;
background:hsla(0,0%,100%,.9)
}
.v[data-class=v] .vcards .vcard .vquote {
padding-left:1em;
border-left:1px dashed hsla(0,0%,93%,.5)
}
.v[data-class=v] .vcards .vcard .vquote .vimg {
width:2.225em;
height:2.225em
}
.v[data-class=v] .vpage .vmore {
margin:1em 0
}
.v[data-class=v] .clear {
content:"";
display:block;
clear:both
}
@-webkit-keyframes spin {
0% {
-webkit-transform:rotate(0deg);
transform:rotate(0deg)
}
to {
-webkit-transform:rotate(1turn);
transform:rotate(1turn)
}
}@keyframes spin {
0% {
-webkit-transform:rotate(0deg);
transform:rotate(0deg)
}
to {
-webkit-transform:rotate(1turn);
transform:rotate(1turn)
}
}@-webkit-keyframes pulse {
50% {
background:#dcdcdc
}
}@keyframes pulse {
50% {
background:#dcdcdc
}
}.v[data-class=v] .vspinner {
width:22px;
height:22px;
display:inline-block;
border:6px double #a0a0a0;
border-top-color:transparent;
border-bottom-color:transparent;
border-radius:50%;
-webkit-animation:spin 1s infinite linear;
animation:spin 1s infinite linear;
position:relative;
vertical-align:middle;
margin:0 5px
}
.dark .v[data-class=v] .status-bar,.dark .v[data-class=v] .veditor,.dark .v[data-class=v] .vinput,.dark .v[data-class=v] p,.dark .v[data-class=v] pre code,.night .v[data-class=v] .status-bar,.night .v[data-class=v] .veditor,.night .v[data-class=v] .vinput,.night .v[data-class=v] p,.night .v[data-class=v] pre code,.theme__dark .v[data-class=v] .status-bar,.theme__dark .v[data-class=v] .veditor,.theme__dark .v[data-class=v] .vinput,.theme__dark .v[data-class=v] p,.theme__dark .v[data-class=v] pre code,[data-theme=dark] .v[data-class=v] .status-bar,[data-theme=dark] .v[data-class=v] .veditor,[data-theme=dark] .v[data-class=v] .vinput,[data-theme=dark] .v[data-class=v] p,[data-theme=dark] .v[data-class=v] pre code {
color:#b2b2b5
}
.dark .v[data-class=v] .vsys,.dark .v[data-class=v] .vtime,.night .v[data-class=v] .vsys,.night .v[data-class=v] .vtime,.theme__dark .v[data-class=v] .vsys,.theme__dark .v[data-class=v] .vtime,[data-theme=dark] .v[data-class=v] .vsys,[data-theme=dark] .v[data-class=v] .vtime {
color:#929298
}
.dark .v[data-class=v] code,.dark .v[data-class=v] pre,.dark .v[data-class=v] pre code,.night .v[data-class=v] code,.night .v[data-class=v] pre,.night .v[data-class=v] pre code,.theme__dark .v[data-class=v] code,.theme__dark .v[data-class=v] pre,.theme__dark .v[data-class=v] pre code,[data-theme=dark] .v[data-class=v] code,[data-theme=dark] .v[data-class=v] pre,[data-theme=dark] .v[data-class=v] pre code {
color:#929298;
background-color:#151414
}
.dark .v[data-class=v] .vwrap,.night .v[data-class=v] .vwrap,.theme__dark .v[data-class=v] .vwrap,[data-theme=dark] .v[data-class=v] .vwrap {
border-color:#b2b2b5
}
.dark .v[data-class=v] .vicon,.night .v[data-class=v] .vicon,.theme__dark .v[data-class=v] .vicon,[data-theme=dark] .v[data-class=v] .vicon {
fill:#b2b2b5
}
.dark .v[data-class=v] .vicon.actived,.night .v[data-class=v] .vicon.actived,.theme__dark .v[data-class=v] .vicon.actived,[data-theme=dark] .v[data-class=v] .vicon.actived {
fill:#66b1ff
}
.dark .v[data-class=v] .vbtn,.night .v[data-class=v] .vbtn,.theme__dark .v[data-class=v] .vbtn,[data-theme=dark] .v[data-class=v] .vbtn {
color:#b2b2b5;
border-color:#b2b2b5
}
.dark .v[data-class=v] .vbtn:hover,.night .v[data-class=v] .vbtn:hover,.theme__dark .v[data-class=v] .vbtn:hover,[data-theme=dark] .v[data-class=v] .vbtn:hover {
color:#66b1ff;
border-color:#66b1ff
}
.dark .v[data-class=v] a:hover,.night .v[data-class=v] a:hover,.theme__dark .v[data-class=v] a:hover,[data-theme=dark] .v[data-class=v] a:hover {
color:#d7191a
}
.dark .v[data-class=v] .vcards .vcard .vcontent.expand:before,.night .v[data-class=v] .vcards .vcard .vcontent.expand:before,.theme__dark .v[data-class=v] .vcards .vcard .vcontent.expand:before,[data-theme=dark] .v[data-class=v] .vcards .vcard .vcontent.expand:before {
background:-webkit-gradient(linear,left top,left bottom,from(rgba(0,0,0,.3)),to(rgba(0,0,0,.7)));
background:linear-gradient(180deg,rgba(0,0,0,.3),rgba(0,0,0,.7))
}
.dark .v[data-class=v] .vcards .vcard .vcontent.expand:after,.night .v[data-class=v] .vcards .vcard .vcontent.expand:after,.theme__dark .v[data-class=v] .vcards .vcard .vcontent.expand:after,[data-theme=dark] .v[data-class=v] .vcards .vcard .vcontent.expand:after {
background:rgba(0,0,0,.7)
}
@media (prefers-color-scheme:dark) {
.v[data-class=v] .status-bar,.v[data-class=v] .veditor,.v[data-class=v] .vinput,.v[data-class=v] p,.v[data-class=v] pre code {
color:#b2b2b5
}
.v[data-class=v] .vsys,.v[data-class=v] .vtime {
color:#929298
}
.v[data-class=v] code,.v[data-class=v] pre,.v[data-class=v] pre code {
color:#929298;
background-color:#151414
}
.v[data-class=v] .vwrap {
border-color:#b2b2b5
}
.v[data-class=v] .vicon {
fill:#b2b2b5
}
.v[data-class=v] .vicon.actived {
fill:#66b1ff
}
.v[data-class=v] .vbtn {
color:#b2b2b5;
border-color:#b2b2b5
}
.v[data-class=v] .vbtn:hover {
color:#66b1ff;
border-color:#66b1ff
}
.v[data-class=v] a:hover {
color:#d7191a
}
.v[data-class=v] .vcards .vcard .vcontent.expand:before {
background:-webkit-gradient(linear,left top,left bottom,from(rgba(0,0,0,.3)),to(rgba(0,0,0,.7)));
background:linear-gradient(180deg,rgba(0,0,0,.3),rgba(0,0,0,.7))
}
.v[data-class=v] .vcards .vcard .vcontent.expand:after {
background:rgba(0,0,0,.7)
}
}