Timers
You can calculate time using timers. They can measure time as well as trigger actions at set intervals or when the timer stops.
Timer properties
id
: Timer ID. Required field.duration
: Timer period in milliseconds. If set to0
or not set, the timer continues running indefinitely until the stop event is triggered.tick_interval
: Interval between timer ticks. The actual tick rate may differ from the specified value by a few milliseconds: we deliberately made it so that the variable stores the actual time that's not rounded up or down.value_variable
: Variable that stores the current timer value. It's updated every tick. This value reflects actual elapsed time, so it may not always be a multiple oftick_interval
and may include additional milliseconds after the last tick.tick_actions
: Array of actions to execute on each timer tick.end_actions
: Array of actions to execute when the timer stops.
Timers are declared in the card
object:
{
"templates": {...},
"card": {
"timers": [
{
"id": "ticker",
"duration": "@{timer_duration}",
"tick_interval": "@{timer_interval}",
"value_variable": "timer_value",
"tick_actions": [],
"end_actions": []
}
],
...
}
}
Controls
To control a timer from the layout, use the following actions:
Action |
Description |
|
Start the timer. |
|
Stop the timer and execute |
|
Pause the timer. |
|
Resume the timer. |
|
Interrupt the timer. |
|
Restart the timer (runs |
View an interactive example
Learn more
Follow DivKit news in the Telegram channel: http://t.me/divkit_news
You can also discuss topics of interest in the DivKit user community in Telegram: https://t.me/divkit_community_ru