Animated Number
Animated counting number display.
Preview
1,234
Arguments
animated_number(value=1234, duration=1000)
Usage
views.py
python
from djust import LiveView
from djust.components import AnimatedNumber
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = AnimatedNumber(value=1234, duration=1000)my_template.html
django
{{ component }}Needs its script on the page: <script src="{% static 'djust_components/animated-number.js' %}"></script>. djust ships it; without it the markup renders but does not update in the browser.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| value | float | 0 | Target numeric value. |
| prefix | str | '' | Text before the number (e.g. "$"). |
| suffix | str | '' | Text after the number (e.g. "%"). |
| duration | int | 800 | Animation duration in ms (default: 800). |
| decimals | int | 0 | Number of decimal places (default: 0). |
| separator | str | ',' | Thousands separator (default: ","). |
| custom_class | str | '' | Additional CSS classes. |
| **kwargs | — passed to `Component.__init__`: `name=` identifies the instance in the events it sends, `id=` sets `component.id`, and any other keyword is kept as state | — | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.animated_number | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 2 of this component's classes at line 2429, 2431. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |