之前写了一个博客中能用到的代码,这是第二篇
这篇文章介绍了如何添加旋转小人每日诗句

>旋转小人

参考自CodepenCodePen — 前端利器分享

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<div class="twopeople">
<div class="container" style="height:200px;">
<canvas class="illo" width="800" height="800" style="max-width: 200px; max-height: 200px; touch-action: none; width: 640px; height: 640px;"></canvas>
</div>
<script src="https://cdn.jsdelivr.net/gh/Justlovesmile/CDN/js/twopeople1.js"></script>
<script src="https://cdn.jsdelivr.net/gh/Justlovesmile/CDN/js/zdog.dist.js"></script>
<script id="rendered-js" src="https://cdn.jsdelivr.net/gh/Justlovesmile/CDN/js/twopeople.js"></script>
<style>
.twopeople{
margin: 0;
align-items: center;
justify-content: center;
text-align: center;
}
canvas {
display: block;
margin: 0 auto;
cursor: move;
}
</style>
</div>

>念两句诗

参考自Sakura主题在留言页动态诗句 Sakura主题美化第三弹

1
2
3
4
5
6
7
8
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<div class="poem-wrap">
<div class="poem-border poem-left"></div>
<div class="poem-border poem-right"></div>
<h1>念两句诗</h1>
<p id="poem">挑选中...</p>
<p id="info">
</div>
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
/*诗*/
.poem-wrap {
position: relative;
width: 730px;
max-width: 80%;
border: 2px solid #797979;
border-top: none;
text-align: center;
margin: 80px auto;
}

.poem-wrap h1 {
position: relative;
margin-top: -20px;
display: inline-block;
letter-spacing: 4px;
color: #797979
}

.poem-wrap p {
width: 70%;
margin: auto;
line-height: 30px;
color: #797979;
}

.poem-wrap p#poem {
font-size: 25px;
}

.poem-wrap p#info {
font-size: 15px;
margin: 15px auto;
}

.poem-border {
position: absolute;
height: 2px;
width: 27%;
background-color: #797979;
}

.poem-right {
right: 0;
}

.poem-left {
left: 0;
}

@media (max-width: 685px) {
.poem-border {
width: 18%;
}
}

@media (max-width: 500px) {
.poem-wrap {
margin-top: 60px;
margin-bottom: 20px;
border-top: 2px solid #797979;
}

.poem-wrap h1 {
margin: 20px 6px;
}

.poem-border {
display: none;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*诗*/
if ($("div").hasClass("poem-wrap")) {
get_poem('#poem', '#info')
}
function get_poem(poem_ele, info_ele) {
var poem = document.querySelector(poem_ele);
var info = document.querySelector(info_ele);
var xhr = new XMLHttpRequest();
xhr.open('get', 'https://v2.jinrishici.com/one.json');
xhr.withCredentials = true;
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
var data = JSON.parse(xhr.responseText);
poem.innerHTML = data.data.content;
info.innerHTML = '【' + data.data.origin.dynasty + '】' + data.data.origin.author + '《' + data.data.origin.title + '》';
}
};
xhr.send();
}