This is the 12th day of my participation in the More text Challenge. For details, see more text Challenge
preface
Today is the first day of the Dragon Boat Festival holiday, thinking to add some interesting things to my blog home page, thinking, ready to add a toxic chicken soup in the home page, toxic chicken soup must be random, each refresh will have different sentences, and then through the typewriter effect. In order to consolidate the JS foundation, I decided to do a Demo with native JS first, roll up your sleeves and do it, the effect is as follows.
Poison chicken soup interface
Poison chicken soup sentence thousands of thousands of thousands, I have no condition to make a database and interface out, so of course, it is best to have the most fragrant free ready-made! I searched for a long time, and finally used the Skyline data API interface, not to advertise ha, after all, my small amount of reading has not asked me to advertise ~
First, briefly summarize the open API interface of skyline data:
The name of the interface | Address of the interface | instructions |
---|---|---|
Wechat link conversion | www.tianapi.com/apiview/89 | Convert a temporary link to a permanent link |
Query the full text of wechat | www.tianapi.com/apiview/88 | Obtain wechat full text profile picture and other information |
Comprehensive news | www.tianapi.com/apiview/87 | Mixed output full channel news data |
Twenty-four Solar Terms | www.tianapi.com/apiview/86 | Lunar calendar data interface |
Automotive news | www.tianapi.com/apiview/85 | Auto industry news and information interface |
Blood type matching | www.tianapi.com/apiview/84 | The relationship between blood type and personality and marriage |
Chinese zodiac matched | www.tianapi.com/apiview/83 | The Traditional Chinese zodiac is paired with 12 animals |
Image coding | www.tianapi.com/apiview/82 | Convert the image to Base64 encoding |
Wechat intelligent interface | www.tianapi.com/apiview/81 | Access to wechat public and mini program platforms |
Earthy… | www.tianapi.com/apiview/80 | Sweet to greasy mouth of the dialect interface |
Internet Information | www.tianapi.com/apiview/79 | Internet news and information interface |
The constellation chart | www.tianapi.com/apiview/78 | Check your daily horoscope |
Wechat latest article | www.tianapi.com/apiview/77 | Access to the public number of the latest article interface |
Malicious IP Detection | www.tianapi.com/apiview/75 | Interface for real-time malicious IP detection |
Malicious link detection | www.tianapi.com/apiview/74 | Real-time malicious link detection interface |
Access to Web information | www.tianapi.com/apiview/73 | Interface for getting header information |
The weather forecast | www.tianapi.com/apiview/72 | One-week weather forecast API |
Chinese characters to Pinyin | www.tianapi.com/apiview/70 | Chinese characters to pinyin API interface |
Anime information | www.tianapi.com/apiview/69 | Whole network hot animation information API |
Network hot spots | www.tianapi.com/apiview/68 | Search for hot spots in real time |
Extract web page images | www.tianapi.com/apiview/67 | Support to extract images from web pages by format |
Press the full | www.tianapi.com/apiview/66 | This interface can get the full news content |
The channel list | www.tianapi.com/apiview/65 | Sky line data news channel ID data |
Financial news | www.tianapi.com/apiview/64 | Stay aware of the financial issues around you |
Game information | www.tianapi.com/apiview/63 | A daily selection of game news |
One sentence in English | www.tianapi.com/apiview/62 | A philosophical sentence |
Beautiful poem, | www.tianapi.com/apiview/61 | Poems and sentences with beautiful artistic conception |
Three hundred tang poems | www.tianapi.com/apiview/60 | A very popular anthology of tang poetry |
Tang poetry books | www.tianapi.com/apiview/59 | Tang Dynasty poetry corpus API interface |
The CBA news | www.tianapi.com/apiview/58 | CBA news consulting API interface |
Jane said history | www.tianapi.com/apiview/57 | History in a word |
Little jokes | www.tianapi.com/apiview/56 | Taste different life |
Real-time stock price | www.tianapi.com/apiview/55 | High quality stock quotes in real time |
In mandarin | www.tianapi.com/apiview/54 | A playful verbal rhyme |
Beautiful sentences | www.tianapi.com/apiview/53 | Beautiful sentence a sentence signature |
Language translation API | www.tianapi.com/apiview/52 | Support multi-language translation |
Common interface | www.tianapi.com/apiview/51 | Support all news channel data classification output |
Turn web API | www.tianapi.com/apiview/50 | To achieve arbitrary graphic list class information output |
The english-chinese dictionary | www.tianapi.com/apiview/49 | Contains explanations of all common English words in Chinese |
Chinese dictionary | www.tianapi.com/apiview/48 | Chinese dictionary API interface |
Skywalking robot | www.tianapi.com/apiview/47 | An interesting AI robot |
Chinese word segmentation API | www.tianapi.com/apiview/46 | Highly efficient Chinese word segmentation interface |
Chinese old calendar | www.tianapi.com/apiview/45 | Chinese old Calendar API |
Where the phone belongs | www.tianapi.com/apiview/44 | Example Query the region to which a mobile phone number belongs |
IP Address Query | www.tianapi.com/apiview/43 | This interface is used to query the latest IP address library |
Constellation matching | www.tianapi.com/apiview/42 | Support single and double matching search |
Two-dimensional code decoding | www.tianapi.com/apiview/41 | Qr code decoding API interface |
Qr code | www.tianapi.com/apiview/40 | Qr code API interface |
God replies | www.tianapi.com/apiview/39 | A divine reply woke up a dreamer |
xiehouyu | www.tianapi.com/apiview/38 | Short, funny, riddle-like sentences |
Tongue twister | www.tianapi.com/apiview/37 | Fertilizer evaporates when you first enter the river |
The network name | www.tianapi.com/apiview/36 | Pick a random, nice screen name |
Url conversion | www.tianapi.com/apiview/35 | Turn long complex urls into short links |
The stock market terms | www.tianapi.com/apiview/34 | The sea is endless |
Network hot words | www.tianapi.com/apiview/33 | The catchwords on the Internet |
Place a riddle | www.tianapi.com/apiview/32 | Guess the city name as prompted |
The first world war to the end | www.tianapi.com/apiview/31 | A stop to the end of the quiz application essential |
allusion | www.tianapi.com/apiview/30 | Know where each idiom comes from |
Today in History | www.tianapi.com/apiview/29 | History today API |
Brain teaser | www.tianapi.com/apiview/28 | Brain teaser API interface |
Birthday character | www.tianapi.com/apiview/27 | Indicates that personality has something to do with birthdays |
catchphrase | www.tianapi.com/apiview/26 | Learn to use famous words |
Shocking jokes | www.tianapi.com/apiview/25 | Laugh for ten years |
Duke of zhou interprets | www.tianapi.com/apiview/24 | Dreams may indicate something |
The menu query | www.tianapi.com/apiview/23 | Essential API for living kitchen applications |
Artificial intelligence (ai) | www.tianapi.com/apiview/22 | AI AI industry news and information API |
Blockchain News | www.tianapi.com/apiview/21 | Blockchain industry related news and information API |
The IT information | www.tianapi.com/apiview/20 | IT industry related news and information API |
VR technology | www.tianapi.com/apiview/19 | VR News and information API |
Beautiful pictures | www.tianapi.com/apiview/18 | Beauty picture API |
anecdotes | www.tianapi.com/apiview/17 | World News information API |
Health knowledge | www.tianapi.com/apiview/16 | Health knowledge health information article information |
The tourist information | www.tianapi.com/apiview/15 | Tourist attractions news and information API |
Mobile Internet | www.tianapi.com/apiview/14 | Mobile Internet industry information API |
Military news | www.tianapi.com/apiview/13 | Military Information API |
Apple news | www.tianapi.com/apiview/12 | Apple dynamic API for products |
Business news | www.tianapi.com/apiview/11 | Internet Industry News AP |
Science and technology news | www.tianapi.com/apiview/10 | Information technology industry news |
Football news | www.tianapi.com/apiview/9 | National football news updates in real time |
The NBA news | www.tianapi.com/apiview/8 | NBA News Feed API |
Sports news | www.tianapi.com/apiview/7 | Domestic and Foreign Sports API |
Entertainment news | www.tianapi.com/apiview/6 | Entertainment news API service |
International news | www.tianapi.com/apiview/5 | International news API interface service |
The national news | www.tianapi.com/apiview/4 | Domestic news API interface service |
Social news | www.tianapi.com/apiview/3 | Keep abreast of social news and events |
WeChat home page | www.tianapi.com/apiview/2 | Real-time synchronization of wechat homepage articles |
WeChat selection | www.tianapi.com/apiview/1 | Selected articles from wechat public account |
There are still a lot of interesting functions, can make a lot of interesting things. However, the interface we need to use is not in the open interface above, but the free interface applied after the registration of free members.
After signing up for the free membership, we went directly to the interface book page. As you can see, there are many interesting interfaces to offer:
We can search here for the interface we want, search for “bad chicken soup”, and the results are as follows:
Click in, there are call examples, return parameters and so on, directly apply for:
After the application is completed, this interface can be found in the interface I applied for in data Management:
You can see the free interface of toxic chicken soup is 100 times, but it is enough for me. If it is really not enough, you can also use day beans to offset, how to get specific day beans and so on, I am not quite clear, not to discuss here.
Ok, now that we’ve successfully got the chicken soup interface, let’s implement a vertical typewriter effect!
Vertical typewriter effect
Vertical version of the typewriter, must be the text first stand up (like other nonsense), here I adopt the method of the simple and crude, within this typewriter effect of the box, each column is a p tag, p tag contains span, span tags inside is text, to p label the width of a word, width is not enough, the text will automatically wrap. The basic layout code looks like this:
<style>
p {
float: left;
width: 1em;
height: 100%;
font-size: 14px;
margin: 5px;
text-align: left;
}
</style>
<div class="signature">
<p>
<span>Try to fill the days</span>
</p>
<p>
<span>Don't remind me how lonely I am</span>
</p>
</div>
Copy the code
The effect is as follows:
Now that the CSS effect is complete, let’s look at how the typewriter effect works:
To achieve the effect of a typewriter, we have to consider the following aspects:
- Text should be cut according to punctuation and converted into an array, which can be used with regular expressions.
- The text is shown one by one, so using the substring method of a string is the perfect fit.
- The cursor flicker effect can be realized directly with JQ fadeOut and fadeIn.
So I immediately wrote the following code:
let text // The printed text
let arr // An array of text cut according to punctuation
let i = 0 // The initial array loop is subscripted from 0
function daziji(i) {
let ps = $(".signature").children("p") // Gets the number of lines of text in the box
if (i == ps.length) return false // If there are 0 lines of text, terminate the function directly
let index = 0 // The number of words in the current line
let dazi = setInterval(function() {
ps[i].childNodes[1].innerText = "I"
$(ps[i].childNodes[1]).fadeOut(300).fadeIn(300)
ps[i].childNodes[0].innerText = arr[i].substring(0, index++)
if (index > arr[i].length) {
$(ps[i].childNodes[1]).remove()
clearInterval(dazi)
daziji(++i)
}
}, 400)}Copy the code
Call the chicken soup interface to get the sentence, and then display it on the page, as follows:
// Call chicken soup via the skyline interface
function getSoup() {
$.ajax({
type: "get".url:
/ / poison chicken soup
"Https://api.tianapi.com/txapi/dujitang/index?key=" the value of your key.success: function(success) {
if (success.code == 200) {
text = success.newslist[0].content
var reg = / [, | |;; |;; | :; | :; |.; |.; |?; |?; |;] /g // The regular section only checks for these punctuation marks
arr = text.split(reg)
for (var j = 0; j < arr.length; j++) {
let pp = "<p><span></span><span></span></p>"
$(".signature").append(pp)
}
daziji(i)
}
},
error: function(error) {
console.error("Error obtaining data" + error)
text = The night gave me black eyes, but I used them to look for light
var reg = / [, | |;; |;; | :; | :; |.; |.; |?; |?; |;] /g
arr = text.split(reg)
for (var j = 0; j < arr.length; j++) {
let pp = "<p><span></span><span></span></p>"
$(".signature").append(pp)
}
daziji(i)
}
})
}
Copy the code
Check out the results:
Works perfectly! After all, the code is written by their own hands, especially the Dragon Boat Festival holiday, still tirelessly knock code, so it looks particularly have a sense of achievement!
Afterword.
After all, it was the first day of the holiday, played a day, came back in the evening to achieve this effect immediately sorted out the article to send, more or less will be thoughtless, some code rough and can be optimized, of course, the most important thing is fun. If this article has helped you, I hope to like the ice cube, if you have better ideas are also welcome to comment ~
PS: today is the 12th day for me to participate in the gold digging challenge, the Dragon Boat Festival is still trying hard to look at the article, it has been 12 days! Where there is a will, there is a way. Come on, everybody
The list of more challenging articles is as follows:
- Flex layout container elements and project elements attributes
- 2021.06.02 how to play with CSS Gradient Background
- How to Use SVG to create Text Effects along Arbitrary Paths
- 2021.06.04 “Front-end code specification of 3 categories and 15 subcategories, let the team code be standardized!”
- Git Commit Specification for team management: How many people don’t write commit records?
- 2021.06.06 “How to Control CSS mouse Style and Expand mouse Click area | Weekend study”
- 2021.06.07 “Pure CSS implementation: imitation gold mining account password login, the red panda wu eye action switch small Egg”
- On Prototypes and Prototype Chains in 11 Aspects
- A Closer Look at JavaScript scope and Scope Chains
- What is a closure in JavaScript?
- 2021.06.11 “Cool Video Text Mask effect with pure CSS”