Skip to content

Commit

Permalink
Introduce deleteSpeed feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmacarthur committed Jun 6, 2016
1 parent 1060dcc commit 386eebf
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ To get started, first select a license:

Get it from this repo, or from the following sources:

* <strong><a href="https://www.jsdelivr.com/projects/jquery.typeit">CDN:</a></strong> Include `https://cdn.jsdelivr.net/jquery.typeit/4.1.0/typeit.min.js` or `https://cdnjs.cloudflare.com/ajax/libs/typeit/4.1.0/typeit.min.js` on your page.
* <strong><a href="https://www.jsdelivr.com/projects/jquery.typeit">CDN:</a></strong> Include `https://cdn.jsdelivr.net/jquery.typeit/4.2.0/typeit.min.js` or `https://cdnjs.cloudflare.com/ajax/libs/typeit/4.2.0/typeit.min.js` on your page.
* <strong><a href="https://www.npmjs.com/package/typeit">npm:</a></strong> Install with `npm install typeit`.

### Hook It Up

1. Load jQuery and typeit.js on your page.

```html
<script src="jquery-2.1.4.min.js"></script>
<script src="jquery.js"></script>
<script src="typeit.js"></script>
```

Expand Down
29 changes: 19 additions & 10 deletions dev/typeit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* jQuery TypeIt
* @author Alex MacArthur (http://macarthur.me)
* @version 4.1.0
* @version 4.2.0
* @copyright 2016 Alex MacArthur
* @description Types out a given string or strings.
*/
Expand All @@ -21,6 +21,7 @@
this.d = {
strings: [],
speed: 100,
deleteSpeed: undefined,
lifeLike: true,
cursor: true,
cursorSpeed: 1000,
Expand Down Expand Up @@ -131,8 +132,8 @@
// do the work that matters
this.tTO = setTimeout(function() {

// _randomize the timeout each time, if that's your thing
this._random(this);
// randomize the timeout each time, if that's your thing
this._setPace(this);

// "_print" the character
// if an opening HTML tag is found and we're not already pringing inside a tag
Expand Down Expand Up @@ -161,7 +162,7 @@
this._executeQueue();
}

}.bind(this), this.DT);
}.bind(this), this.typePace);
},

pause : function(time) {
Expand Down Expand Up @@ -202,7 +203,7 @@

this.dTO = setTimeout(function() {

this._random();
this._setPace();

var a = this.tel.html().split("");

Expand Down Expand Up @@ -268,7 +269,7 @@
} else {
this._executeQueue();
}
}.bind(this), this.DT/3);
}.bind(this), this.deletePace);
},

_isVisible : function() {
Expand Down Expand Up @@ -342,12 +343,20 @@
}
},

_random : function() {
var s = this.s.speed;
var r = s/2;
this.DT = this.s.lifeLike ? Math.abs(Math.random() * ((s+r) - (s-r)) + (s-r)) : s;
_setPace : function() {
var typeSpeed = this.s.speed;
var deleteSpeed = this.s.deleteSpeed !== undefined ? this.s.deleteSpeed : this.s.speed/3;
var typeRange = typeSpeed/2;
var deleteRange = deleteSpeed/2;

this.typePace = this.s.lifeLike ? this._randomInRange(typeSpeed, typeRange) : typeSpeed;
this.deletePace = this.s.lifeLike ? this._randomInRange(deleteSpeed, deleteRange) : deleteSpeed;
},

_randomInRange : function(value, range) {
return Math.abs(Math.random() * ((value+range) - (value-range)) + (value-range));
},

/*
Convert each string in the array to a sub-array. While happening, search the subarrays for HTML tags.
When a complete tag is found, slice the subarray to get the complete tag, insert it at the correct index,
Expand Down
2 changes: 1 addition & 1 deletion dev/typeit.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 19 additions & 10 deletions dist/typeit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* jQuery TypeIt
* @author Alex MacArthur (http://macarthur.me)
* @version 4.1.0
* @version 4.2.0
* @copyright 2016 Alex MacArthur
* @description Types out a given string or strings.
*/
Expand All @@ -21,6 +21,7 @@
this.d = {
strings: [],
speed: 100,
deleteSpeed: undefined,
lifeLike: true,
cursor: true,
cursorSpeed: 1000,
Expand Down Expand Up @@ -131,8 +132,8 @@
// do the work that matters
this.tTO = setTimeout(function() {

// _randomize the timeout each time, if that's your thing
this._random(this);
// randomize the timeout each time, if that's your thing
this._setPace(this);

// "_print" the character
// if an opening HTML tag is found and we're not already pringing inside a tag
Expand Down Expand Up @@ -161,7 +162,7 @@
this._executeQueue();
}

}.bind(this), this.DT);
}.bind(this), this.typePace);
},

pause : function(time) {
Expand Down Expand Up @@ -202,7 +203,7 @@

this.dTO = setTimeout(function() {

this._random();
this._setPace();

var a = this.tel.html().split("");

Expand Down Expand Up @@ -268,7 +269,7 @@
} else {
this._executeQueue();
}
}.bind(this), this.DT/3);
}.bind(this), this.deletePace);
},

_isVisible : function() {
Expand Down Expand Up @@ -342,12 +343,20 @@
}
},

_random : function() {
var s = this.s.speed;
var r = s/2;
this.DT = this.s.lifeLike ? Math.abs(Math.random() * ((s+r) - (s-r)) + (s-r)) : s;
_setPace : function() {
var typeSpeed = this.s.speed;
var deleteSpeed = this.s.deleteSpeed !== undefined ? this.s.deleteSpeed : this.s.speed/3;
var typeRange = typeSpeed/2;
var deleteRange = deleteSpeed/2;

this.typePace = this.s.lifeLike ? this._randomInRange(typeSpeed, typeRange) : typeSpeed;
this.deletePace = this.s.lifeLike ? this._randomInRange(deleteSpeed, deleteRange) : deleteSpeed;
},

_randomInRange : function(value, range) {
return Math.abs(Math.random() * ((value+range) - (value-range)) + (value-range));
},

/*
Convert each string in the array to a sub-array. While happening, search the subarrays for HTML tags.
When a complete tag is found, slice the subarray to get the complete tag, insert it at the correct index,
Expand Down
Loading

0 comments on commit 386eebf

Please sign in to comment.