阅读背景:

JavaScript模拟实现键盘打字效果

来源:互联网 

!--NEWSZW_HZH_BEGIN--

$(function () {
 
 
      var input_type = {
        init:function ($obj) {
          this.name = $obj.html().split("")
          this.length = this.name.length;
          this.i = 0;
        },
        pri:function () {
          var $this = this
          //在此处只能应用闭包,由于windown.settimeout使函数的this指向object windown,而非原型链的this对象。而此时我须要递归,所以只能将this对象传到闭包内,递归匿名的闭包函数。
          return (function () {
            if ($this.i > $this.length) {
              window.clearTimeout(Go)
              return false;
            }
            var char = $this.name
            $(".div1").append(char[$this.i])
            $this.i++
            var Go = window.setTimeout(arguments.callee, 100)//在这里arguments.callee妙用由因而匿名闭包,调用函数本身。
          })
        }
      }
 
 
//树立class类
      function Input_type() {
        this.init.apply(this, arguments)
      }
 
      Input_type.prototype = input_type
 
//创立实例
      var p = new Input_type($(".content"))
      p.pri()()
 
    });
$(function () {
 
 
      




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: