Travis build: 2032
This commit is contained in:
37
README.md
37
README.md
@ -197,6 +197,7 @@ average(1, 2, 3);
|
|||||||
* [`arrayToHtmlList`](#arraytohtmllist)
|
* [`arrayToHtmlList`](#arraytohtmllist)
|
||||||
* [`bottomVisible`](#bottomvisible)
|
* [`bottomVisible`](#bottomvisible)
|
||||||
* [`copyToClipboard`](#copytoclipboard-)
|
* [`copyToClipboard`](#copytoclipboard-)
|
||||||
|
* [`counter`](#counter-)
|
||||||
* [`createElement`](#createelement)
|
* [`createElement`](#createelement)
|
||||||
* [`createEventHub`](#createeventhub-)
|
* [`createEventHub`](#createeventhub-)
|
||||||
* [`currentURL`](#currenturl)
|
* [`currentURL`](#currenturl)
|
||||||
@ -3077,6 +3078,42 @@ copyToClipboard('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard.
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### counter 
|
||||||
|
|
||||||
|
Creates a counter with the specified range, step and duration for the specified selector.
|
||||||
|
|
||||||
|
Check if `step` has the proper sign and change it accordingly.
|
||||||
|
Use `setInterval()` in combination with `Math.abs()` and `Math.floor()` to calculate the time between each new text draw.
|
||||||
|
Use `document.querySelector().innerHTML` to update the value of the selected element.
|
||||||
|
Omit the fourth parameter, `step`, to use a default step of `1`.
|
||||||
|
Omit the fifth parameter, `duration`, to use a default duration of `2000`ms.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const counter = (selector, start, end, step = 1, duration = 2000) => {
|
||||||
|
let current = start,
|
||||||
|
_step = (end - start) * step < 0 ? -step : step,
|
||||||
|
timer = setInterval(() => {
|
||||||
|
current += _step;
|
||||||
|
document.querySelector(selector).innerHTML = current;
|
||||||
|
if (current >= end) document.querySelector(selector).innerHTML = end;
|
||||||
|
if (current >= end) clearInterval(timer);
|
||||||
|
}, Math.abs(Math.floor(duration / (end - start))));
|
||||||
|
return timer;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
counter('#my-id', 1, 1000, 5, 2000); // Creates a 2-second timer for the element with id="my-id"
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### createElement
|
### createElement
|
||||||
|
|
||||||
Creates an element from a string (without appending it to the document).
|
Creates an element from a string (without appending it to the document).
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -10,15 +10,15 @@ Omit the fifth parameter, `duration`, to use a default duration of `2000`ms.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const counter = (selector, start, end, step = 1, duration = 2000) => {
|
const counter = (selector, start, end, step = 1, duration = 2000) => {
|
||||||
let current = start,
|
let current = start,
|
||||||
_step = (end - start) * step < 0 ? -step : step,
|
_step = (end - start) * step < 0 ? -step : step,
|
||||||
timer = setInterval(() => {
|
timer = setInterval(() => {
|
||||||
current += _step;
|
current += _step;
|
||||||
document.querySelector(selector).innerHTML = current;
|
document.querySelector(selector).innerHTML = current;
|
||||||
if (current >= end) document.querySelector(selector).innerHTML = end;
|
if (current >= end) document.querySelector(selector).innerHTML = end;
|
||||||
if (current >= end) clearInterval(timer);
|
if (current >= end) clearInterval(timer);
|
||||||
}, Math.abs(Math.floor(duration / (end - start))));
|
}, Math.abs(Math.floor(duration / (end - start))));
|
||||||
return timer;
|
return timer;
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user