countup.mdx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. ---
  2. title: Countup
  3. summary: A countup element is used to display numerical data in an interesting way and make the interface more interactive.
  4. libs: countup
  5. description: Display numbers dynamically with countups.
  6. ---
  7. The countup component is used to display numbers dynamically. It is a great way to make the interface more interactive and engaging. The countup component is a simple and easy way to animate numbers in your application.
  8. To be able to use the countup in your application you will need to install the countup.js dependency with `npm install countup.js`.
  9. For more advanced features of countups, click [here](https://inorganik.github.io/countUp.js/) and see what more you can do.
  10. ## Basic usage
  11. 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.
  12. ```html
  13. <h1 data-countup>30000</h1>
  14. ```
  15. The results can be seen in the example below.
  16. ```html example libs="countup" centered
  17. <h1 data-countup>30000</h1>
  18. ```
  19. ## Duration
  20. Set the `duration` to determine how long the animation should take. By default, the duration is set to 2 seconds, but you can modify it as you wish.
  21. ```html
  22. <h1 data-countup='{"duration":4}'>30000</h1>
  23. ```
  24. Look at the example below to see how the duration affects the animation.
  25. ```html example libs="countup" centered vertical separated
  26. <h1 data-countup>30000</h1>
  27. <h1 data-countup='{"duration":4}'>30000</h1>
  28. <h1 data-countup='{"duration":6}'>30000</h1>
  29. ```
  30. ## Starting value
  31. By default the countup will start from zero. If you want to set a different start value use `startVal`.
  32. You can also set the start value to be greater than the final value, so that it counts down instead of up.
  33. ```html
  34. <h1 data-countup='{"startVal":12345}'>30000</h1>
  35. ```
  36. To see how the starting value affects the animation, look at the example below.
  37. ```html example libs="countup" centered vertical separated
  38. <h1 data-countup='{"startVal":12345}'>30000</h1>
  39. <h1 data-countup='{"startVal":47655}'>30000</h1>
  40. ```
  41. ## Decimal places
  42. Set how many decimal numbers should be displayed using `decimalPlaces`. By default, the number of decimal places is set to 0.
  43. ```html
  44. <h1 data-countup='{"decimalPlaces":1}'>3.123</h1>
  45. ```
  46. Look at the example below to see how the number of decimal places affects the animation.
  47. ```html example libs="countup" centered vertical separated height="20rem"
  48. <h1 data-countup>3.123</h1>
  49. <h1 data-countup='{"decimalPlaces":1}'>3.123</h1>
  50. <h1 data-countup='{"decimalPlaces":2}'>3.123</h1>
  51. <h1 data-countup='{"decimalPlaces":3}'>3.123</h1>
  52. ```
  53. ## Easing
  54. Disable easing using `"useEasing": false`. Easing is set to `true` by default, so that the animation speed changes over the course of its duration. Easing can be disabled to make the animation linear.
  55. ```html
  56. <h1 data-countup='{"useEasing": false}'>30000</h1>
  57. ```
  58. Look at the example below to see how easing affects the animation.
  59. ```html example libs="countup" centered vertical separated
  60. <h1 data-countup>30000</h1>
  61. <h1 data-countup='{"useEasing": false}'>30000</h1>
  62. ```
  63. ## Use grouping
  64. Disable grouping using `"useGrouping": false`. Grouping is set to `true` by default, so that the number is displayed with a separator.
  65. ```html
  66. <h1 data-countup='{"useGrouping": false}'>30000</h1>
  67. ```
  68. Example below shows how grouping affects the animation.
  69. ```html example libs="countup" centered vertical separated
  70. <h1 data-countup>30000</h1>
  71. <h1 data-countup='{"useGrouping": false}'>30000</h1>
  72. ```
  73. ## Separator
  74. You can change the default separator using `separator` and specifying the one you wish to use.
  75. ```html
  76. <h1 data-countup='{"separator":" "}'>3000000</h1>
  77. ```
  78. This example shows how the separator affects the animation.
  79. ```html example libs="countup" centered vertical separated
  80. <h1 data-countup>3000000</h1>
  81. <h1 data-countup='{"separator":" "}'>3000000</h1>
  82. ```
  83. ## Decimal separator
  84. You can change the default decimal separator using `decimal` and specifying the one you wish to use.
  85. ```html
  86. <h1 data-countup='{"decimal":","}'>3.12</h1>
  87. ```
  88. Look at the example below to see how the decimal separator affects the animation.
  89. ```html example libs="countup" centered vertical separated
  90. <h1 data-countup='{"decimalPlaces":2}'>3.12</h1>
  91. <h1 data-countup='{"decimalPlaces":2,"decimal":","}'>3.12</h1>
  92. ```
  93. ## Prefix
  94. Set the countup prefix using `prefix` and specifying the prefix you want to add, for instance a currency symbol.
  95. ```html
  96. <h1 data-countup='{"prefix":"$"}'>30000</h1>
  97. ```
  98. Look at the example below to see how the prefix affects the animation.
  99. ```html example libs="countup" centered vertical separated
  100. <h1 data-countup='{"prefix":"$"}'>30000</h1>
  101. <h1 data-countup='{"prefix":"€"}'>30000</h1>
  102. ```
  103. ## Suffix
  104. Set the countup suffix using `suffix` and specifying the suffix you want to add, for instance a percentage symbol.
  105. ```html
  106. <h1 data-countup='{"suffix":"%"}'>300</h1>
  107. ```
  108. Look at the example below to see how the suffix affects the animation.
  109. ```html example libs="countup" centered vertical separated
  110. <h1 data-countup='{"suffix":"%"}'>300</h1>
  111. <h1 data-countup='{"suffix":"‰"}'>300</h1>
  112. ```