zoukankan      html  css  js  c++  java
  • js打字效果

        <script type="text/javascript">

            var text = "JavaScript实现的打字效果";     //预定文字

            var delay = 200;                     //文字出现的时间间隔

            var i = 0;                           //初始化变量 i

            function scrollit() {

                //设置 id 为 demo 的对象内的文字为从变量 text 的 0 开始到 i 间的文字加"_"

                var demo = document.getElementById("demo");

                demo.innerHTML = text.slice(0, i++) + "_";

                if (i > text.length) {              //当 i 大于 text 的文本长度时

                    i = text.length;

                    demo.innerHTML = text.substr(0, i);                      //重设 i 为 0,使文字重新从第一个文字出现

                    //延时执行scrollit()函数,delay*10是为了让显示完整文字的时间长一点

                    setTimeout("scrollit()", delay * 10);

                }

                //否则在delay毫秒后再次执行scrollit()函数

                else setTimeout("scrollit()", delay);

            }

            scrollit() //调用scrollit()函数

        </script>

  • 相关阅读:
    bootstrapValidator重新校验/全选回显
    mybatis遍历map参数查询
    location.href传json字符串
    springmvc异步处理
    intellIJ IDEA学习笔记3
    intellIJ IDEA学习笔记2
    intellIJ IDEA学习笔记
    maven国内镜像
    Docker版本Jenkins的使用
    Docker容器网络
  • 原文地址:https://www.cnblogs.com/wangsx/p/2132605.html
Copyright © 2011-2022 走看看