mirror of
https://github.com/tabler/tabler.git
synced 2025-12-26 11:16:12 +04:00
Add countup functionality and update documentation example
This commit is contained in:
@@ -11,9 +11,7 @@ To be able to use the countup in your application you will need to install the c
|
||||
|
||||
To create a countup, add `data-countup` to any HTML text tag and specify the number which is to be reached. The animation will be triggered as soon as the number enters the viewport.
|
||||
|
||||
```html example
|
||||
<script src="$TABLER_CDN/dist/libs/countup.js/dist/countUp.js"></script>
|
||||
|
||||
```html example libs="countup"
|
||||
<h1 data-countup>30000</h1>
|
||||
```
|
||||
|
||||
|
||||
17
src/js/src/countup.js
Normal file
17
src/js/src/countup.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const elements = document.querySelectorAll('[data-countup]');
|
||||
|
||||
if (elements.length) {
|
||||
elements.forEach(function (element) {
|
||||
let options = {};
|
||||
try {
|
||||
options = element.getAttribute('data-countup') ? JSON.parse(element.getAttribute('data-countup')) : {};
|
||||
} catch (error) {}
|
||||
|
||||
const value = parseInt(element.innerHTML, 10);
|
||||
|
||||
const countUp = new window.countUp.CountUp(element, value, options);
|
||||
if (!countUp.error) {
|
||||
countUp.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
//Vendor
|
||||
|
||||
import "./src/autosize"
|
||||
import "./src/countup"
|
||||
import "./src/input-mask"
|
||||
import "./src/dropdown"
|
||||
import "./src/tooltip"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//Vendor
|
||||
|
||||
import "./src/autosize"
|
||||
import "./src/countup"
|
||||
import "./src/input-mask"
|
||||
import "./src/dropdown"
|
||||
import "./src/tooltip"
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"bootstrap": "bootstrap/dist/js/bootstrap.bundle.min.js",
|
||||
"apexcharts": "apexcharts/dist/apexcharts.min.js",
|
||||
"nouislider": "nouislider/dist/nouislider.min.js",
|
||||
"countup": "countup.js/dist/countUp.js",
|
||||
"countup": "countup.js/dist/countUp.umd.js",
|
||||
"lists": "list.js/dist/list.min.js",
|
||||
"masonry": "https://cdnjs.cloudflare.com/ajax/libs/masonry/4.2.2/masonry.pkgd.min.js",
|
||||
"mapbox": "https://api.mapbox.com/mapbox-gl-js/v1.8.0/mapbox-gl.js",
|
||||
|
||||
Reference in New Issue
Block a user