我是靠谱客的博主 靓丽蜡烛,这篇文章主要介绍Random Quote Machine(格言随机生成器),现在分享给大家,希望可以做个参考。

在Freecodecamp上面做到一个任务,要求是通过API来完成一个格言生成器。

但是在网上找了好多API都不能用,最后在一位博主的博客上面看到了一个API,亲测可用。

效果如下图所示(暂时分享功能还没写好)


查看演示:https://codepen.io/Maktub_/full/rJEReK

github: https://github.com/zxy1029/Random-Quote-Machine

HTML代码:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> <div class="container-fluid"> <div class="card"> <div id="text"> <i class="fa fa-quote-left"></i> <span id="txt"> Mother of mercy, is this the end of Rico?</span> <div class="text-author"> <span id="author">Henry Ford</span> </div> </div> <div class="button"> <a href="https://github.com/zxy1029" class="btn"><i class="fa fa-github"></i></a> <a href="" class="btn"><i class="fa fa-share-alt"></i></i></a> <button class="btn" id="r-btn">New quote</button> </div> </div> <div class="footer">by <a href="https://codepen.io/dashboard/" class="me">zhang</a> </div> </div>

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
body { background-color: #16a085; } .card { width: 550px; margin: 8% auto auto auto; background-color: #FFF; border-radius: 3px; padding:40px 50px; border-style: none; } .footer { text-align: center; color: #fff; } .me { color: #FFF; } .fa-quote-left { color: #16a085; } .text-author { text-align: right; color: #16a085; } .button{ margin-top:30px; } .btn { color: #FFF; font-size: 25px; background-color: #16a085; } #text { text-align:center; color: #000; font-size: 30px; } #txt{ color: #16a085; } #r-btn { float: right; }
复制代码
1
JS代码
复制代码
1
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$(document).ready(function(){ var colors = [ '#27ae60', '#2c3e50', '#f39c12', '#e74c3c', '#9b59b6', '#FB6964', '#342224', "#472E32", "#BDBB99", "#77B1A9", "#73A857"]; var i=0; $("#r-btn").click(function(){ $("body").css({"background-color":colors[i%11]}); $(".btn").css({"background-color":colors[i%11]}); $("#txt").css({"color":colors[i%11]}); $(".fa-quote-left").css({"color":colors[i%11]}); $(".text-author").css({"color":colors[i%11]}); i++; getQuote(); }); var content=""; var author=""; var getQuote = function(){ $.getJSON("https://sslapi.hitokoto.cn/?encode=json",function(json){ content = json["hitokoto"]; author = json["from"]; $("#txt").html(content); $("#author").html("-"+author); }); } });

由于还有很多功能还没有完善,以后还会继续改进。

最后

以上就是靓丽蜡烛最近收集整理的关于Random Quote Machine(格言随机生成器)的全部内容,更多相关Random内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(76)

评论列表共有 0 条评论

立即
投稿
返回
顶部