- <h>用来显示逐渐出现的文字</h>
- <p id="showStr1"></p>
- <div style="display:none" id="string">helloworld </div>
- <script>
- var index = 0;
- var str = document.getElementById("string").innerHTML;
- function type() {
- if(index == str.length) {
- index = 0;
- }
- document.getElementById("showStr1").innerText = str.substring(0, index++);
- }
- setInterval(type, 200); //通过定时器来让文字逐步显示
- </script>
-
结合一言api接口,推送文字到string容器
- <!-- 一言 -->
- <script type="text/javascript" src="https://api.imjad.cn/hitokoto/?cat=&charset=utf-8&length=&encode=js&fun=sync&source="></script>
- <div style="display:none" id="hitokoto"><script>hitokoto()</script>
- </div>
- <script>
- var index = 0;
- var str = document.getElementById("hitokoto").innerText;
- str = str.substring(10, str.length)//裁剪hitokoto()字样
- function type() {
- if(index == str.length) {
- index = 0;
- }
- document.getElementById("showStr").innerText = str.substring(0, index++);
- }
- setInterval(type, 200); //通过定时器来让文字逐步显示
- </script>
-