Animated Number

Animated counting number display.

python 8 params

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

NameTypeDefaultDescription
valuefloat0Target numeric value.
prefixstr''Text before the number (e.g. "$").
suffixstr''Text after the number (e.g. "%").
durationint800Animation duration in ms (default: 800).
decimalsint0Number of decimal places (default: 0).
separatorstr','Thousands separator (default: ",").
custom_classstr''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
FilePathNotes
moduledjust.components.components.animated_numberSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 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.