Skip to content

Commit

Permalink
updated README.md, updated example, changed how to install
Browse files Browse the repository at this point in the history
  • Loading branch information
MattMoony committed Mar 10, 2019
1 parent bb452af commit 20d4d0c
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 10 deletions.
121 changes: 119 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,125 @@
![GitHub release](https://img.shields.io/github/release/MattMoony/10fingersJS.svg) ![GitHub last commit](https://img.shields.io/github/last-commit/MattMoony/10fingersJS.svg) ![GitHub All Releases](https://img.shields.io/github/downloads/MattMoony/10fingersJS/total.svg) ![GitHub repo size in bytes](https://img.shields.io/github/repo-size/MattMoony/10fingersJS.svg) ![GitHub](https://img.shields.io/github/license/MattMoony/10fingersJS.svg)

# 10fingersJS
_A pure JavaScript-Typewriter._

---

This project is still under development, however I hope you'll be able to enjoy the final product / the current framework.
Provide strings and see them magically being typed out on the page. The typer will automatically detect which part of the string should be removed, in order for the new one to correctly appear, so only the necessary parts will be deleted.

## Installation

#### Script tag

```html
<script src='https://cdn.jsdelivr.net/gh/MattMoony/10fingersJS@v1.0/src/tenfingers.js'></script>
```

## Setup

```javascript
let target = document.getElementById('target');
let typer = new TenFingers(target);
```

## Usage

#### Basic Example

In this example we will use TenFingers to type a couple of strings into the [previously](#Setup) specified element.

```javascript
// ...

typer.typeAll([
'!&copy; MattMoony',
'Hello World!',
'Hello Whales!',
'Hello Wales!',
'Hello Water!',
'Hello Mum!',
'&num;great',
'This is a statement',
'This is a statement.',
]);

// ...
```

![Result of code above](./media/01.gif)

#### Or

You can achieve the same, by using a more complex, but easily customizable syntax.

```javascript
// ...

typer.clear()
.type('!&copy; MattMoony')
.pause(1250)
.clear()
.type('Hello World!')
.pause(1250)
.delete('orld!'.length)
.type('hales!')
.pause(1250)
.delete('hales!'.length)
.type('ales!')
.pause(1250)
// and so on ...

// ...
```

#### With options

Now, we will create a customized typer using the _args_ parameter.

```javascript
// ...

let args = {
typingSpeed: 250,
deletingSpeed: 125,
cursorSpeed: .25,
pauseTimeout: 1000,
// pauseTimeoutS: 1,
endTimeout: 3000,
endStringTimeout: 1000,
loop: true,
};
let typer = new TenFingers(target, args);

typer.typeAll([
'Hello World!',
'How are you doing?',
'How are the people around you doing?',
'Great, it was nice talking to you!',
]);

// ...
```

#### HTML strings

You can also pass IDs to the typer, it will then use the content of those elements.

```javascript
// ...

typer.typeAll([
'#some_id',
'#some_other_id',
]);

// ...
```

## Conclusion

That is about it. If you have any further questions or suggestions, feel free to contact me on [twitter](https://twitter.com/Matthia23184857).

---

... Matthias M.
_... Matthias M. (March, 2019)_
7 changes: 4 additions & 3 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ <h1>10fingersJS</h1>
<h3>by MattMoony</h3>
</header>
<article>
<p id="target" class="targets"></p>
<p id="target" class="targets" style="display: none;"></p>
<p id="target2" class="targets"></p>
<p id="target3" class="targets"></p>
<p id="target3" class="targets" style="display: none;"></p>

<div style="display: none;" id="source_div">This is loaded from a hidden div!</div>
</article>

<script type="module" src="./index.js"></script>
<script src="../src/tenfingers.js"></script>
<script src="./index.js"></script>
</body>
</html>
3 changes: 0 additions & 3 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// import TenFingers from 'https://cdn.jsdelivr.net/gh/MattMoony/10fingersJS/tenfingers/tenfingers.js';
import TenFingers from '../src/tenfingers.js';

// -- For performance measuring -- //
let start;

Expand Down
Binary file added media/01.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/tenfingers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TypingEvent {
}
}

export default class TenFingers {
class TenFingers {
constructor(target, args) {
this.target = target;
args = args || {};
Expand Down Expand Up @@ -222,4 +222,4 @@ export default class TenFingers {
callback();
}, t);
}
};
}

0 comments on commit 20d4d0c

Please sign in to comment.