一言添加动态打字机效果
昵称
密码

一言添加动态打字机效果

fl0919
2021-05-04 / 0 评论 / 588 阅读 / 正在检测是否收录...
/

先上效果:

打字机效果的源代码((来源于网络)):

   <div id="chakhsu">
   </div>
   <script>
       var chakhsu = function(r) {
           function t() {
               return b[Math.floor(Math.random() * b.length)]
           }
 
           function e() {
               return String.fromCharCode(94 * Math.random() + 33)
           }
 
           function n(r) {
               for (var n = document.createDocumentFragment(), i = 0; r > i; i++) {
                   var l = document.createElement("span");
                   l.textContent = e(),
                       l.style.color = t(),
                       n.appendChild(l)
               }
               return n
           }
 
           function i() {
               var t = o[c.skillI];
               c.step ? c.step-- : (c.step = g, c.prefixP < l.length ? (c.prefixP >= 0 && (c.text += l[c.prefixP]), c.prefixP++) : "forward" === c.direction ? c.skillP < t.length ? (c.text += t[c.skillP], c.skillP++) : c.delay ? c.delay-- : (c.direction = "backward", c.delay = a) : c.skillP > 0 ? (c.text = c.text.slice(0, -1), c.skillP--) : (c.skillI = (c.skillI + 1) % o.length, c.direction = "forward")),
                   r.textContent = c.text,
                   r.appendChild(n(c.prefixP < l.length ? Math.min(s, s + c.prefixP) : Math.min(s, t.length - c.skillP))),
                   setTimeout(i, d)
           }
           var l = "授人以鱼,",
               o = ["不如授人以渔。", ].map(function(r) {
                   return r + ""
               }),
               a = 2,
               g = 1,
               s = 5,
               d = 75,
               b = ["rgb(110,64,170)", "rgb(150,61,179)", "rgb(191,60,175)", "rgb(228,65,157)", "rgb(254,75,131)", "rgb(255,94,99)", "rgb(255,120,71)", "rgb(251,150,51)", "rgb(226,183,47)", "rgb(198,214,60)", "rgb(175,240,91)", "rgb(127,246,88)", "rgb(82,246,103)", "rgb(48,239,130)", "rgb(29,223,163)", "rgb(26,199,194)", "rgb(35,171,216)", "rgb(54,140,225)", "rgb(76,110,219)", "rgb(96,84,200)"],
               c = {
                   text: "",
                   prefixP: -s,
                   skillI: 0,
                   skillP: 0,
                   direction: "forward",
                   delay: a,
                   step: g
               };
           i()
       };
       chakhsu(document.getElementById('chakhsu'));
   </script>

需要修改的文件joe主题下的public-->aside文件


1.png

  • 注释掉原来的一言
  • 在原动态打字机的基础上修改一些内容
  • 先定义一个数据用于存放自己的诗句
  • 更改原来打字机固定的句子

数组拼接诗词的方法


拼接诗词.png

修改后的代码

           <!--一言修改位置-->
<!--            <div class="tiktok"><p id="heading" class="motto joe_motto"></p></div>-->
<!--            <div id="tiktok"><p id="heading" class="motto joe_motto"></p></div>-->
<!--            自定义一言-->
            <div id="chakhsu">
            </div>
            <script>
                window.onload = function(){
                    chakhsu();
                }

                var chakhsu = function (r) {
                    function t() {
                        return b[Math.floor(Math.random() * b.length)]
                    }

                    function e() {
                        return String.fromCharCode(94 * Math.random() + 33)
                    }

                    function n(r) {
                        for (var n = document.createDocumentFragment(), i = 0; r > i; i++) {
                            var l = document.createElement("span");
                            l.textContent = e(),
                                l.style.color = t(),
                                n.appendChild(l)
                        }
                        return n
                    }

                    function i() {
                        var t = o[c.skillI];
                        c.step ? c.step-- : (c.step = g, c.prefixP < l.length ? (c.prefixP >= 0 && (c.text += l[c.prefixP]), c.prefixP++) : "forward" === c.direction ? c.skillP < t.length ? (c.text += t[c.skillP], c.skillP++) : c.delay ? c.delay-- : (c.direction = "backward", c.delay = a) : c.skillP > 0 ? (c.text = c.text.slice(0, -1), c.skillP--) : (c.skillI = (c.skillI + 1) % o.length, c.direction = "forward")),
                            r.textContent = c.text,
                            r.appendChild(n(c.prefixP < l.length ? Math.min(s, s + c.prefixP) : Math.min(s, t.length - c.skillP))),
                            setTimeout(i, d)
                    }



                    //定义数组
                    var mywords = ["一种可怜生,落日和烟雨","春风桃李花开日,秋雨梧桐叶落时","东风吹柳日初长,雨余芳草斜阳","小池寒绿欲生漪,雨晴还日西","竹枝三唱,为君凄断,东日西边雨","落日暴风雨,归路绕汀湾","天将金玉为风露,曾为高秋几度贫","桃李春风一杯酒,江湖夜雨十年灯","久旱逢甘雨,他乡遇故知","惊沙猎猎风成阵,白雁一声霜有信","落日醉醒问,一春无此寒","梅子欲黄时,又须作,廉纤细雨","蜀天常夜雨,江槛已朝晴","忧喜相寻,风雨过、一江春绿","春意已无多,斜日满帘飞燕","春水无风无浪,春天半雨半晴","帘外雨潺潺,春意阑珊","人言落日是天涯,望极天涯不见家","铿然忽变赤龙飞,雷雨四山黑","春雨断桥人不渡,小舟撑出柳阴来","西风几弄冰肌彻,玲珑晶枕愁双设","铜雀春情,金人秋泪,此恨凭谁雪","不愁屋漏床床湿,且喜溪流岸岸深","玉容寂寞泪阑干,梨花一枝春带雨","随风潜入夜,润物细无声","鼓鞞惊破霓裳,海棠亭北多风雨","游人不管春将老,来往亭前踏落花","三分春色二分愁,更一分风雨","紫黯红愁无绪,日暮春归甚处","万事尽随风雨去,休休,戏马台南金络头","春雨消残冻,温风到冷灰","向深秋,雨馀爽气肃西郊","风怒欲拔木,雨暴欲掀屋","风透春衫,雨透春衫","弦管,弦管,春草昭阳路断","东风吹雨过青山,却望千门草色闲","斗草烟欺罗袂薄,秋千影落春游倦"];


                    var rnumber=Math.floor(Math.random()*36);
                    var getwords=mywords[rnumber]
                    var l = "",
                        // p = document.getElementById("heading").innerText,
                        p = getwords,
                        o = [p,].map(function (r) {
                            return r + ""
                        }),
                        a = 2,
                        g = 1,
                        s = 5,
                        d = 75,
                        b = ["rgb(110,64,170)", "rgb(150,61,179)", "rgb(191,60,175)", "rgb(228,65,157)", "rgb(254,75,131)", "rgb(255,94,99)", "rgb(255,120,71)", "rgb(251,150,51)", "rgb(226,183,47)", "rgb(198,214,60)", "rgb(175,240,91)", "rgb(127,246,88)", "rgb(82,246,103)", "rgb(48,239,130)", "rgb(29,223,163)", "rgb(26,199,194)", "rgb(35,171,216)", "rgb(54,140,225)", "rgb(76,110,219)", "rgb(96,84,200)"],
                        c = {
                            text: "",
                            prefixP: -s,
                            skillI: 0,
                            skillP: 0,
                            direction: "forward",
                            delay: a,
                            step: g
                        };
                    i()
                };
                chakhsu(document.getElementById('chakhsu'));
            </script>
            <!--            自定义一言结束-->

完整的php文件下载:

288

评论

博主关闭了所有页面的评论