javascript - 同一页面上的多个值计数器
问题描述
我正在使用 Pqina 的 Flip 计数器,我需要在同一页面上创建 5 个具有不同值和间隔的值计数器。翻转文档没有提供解决方案如何做到这一点。如何在 html 上添加数据(日期、间隔、持续时间和值的数据)并仅使用一个函数?我尝试了很多在网上找到的技巧(GetAttribute、HTML 上的数据、每个函数等),但我对 JS 并不是很熟悉。我正在尝试使用这个:
<div class="tick" data-did-init="handleTickInit">
<span data-layout="horizontal fit">
<span data-repeat="true" data-transform="arrive(5, .01) -> round -> split -> delay(rtl, 100, 150)">
<span data-view="flip"></span>
</span>
</span>
</div>
function handleTickInit(tick){
// update the value every 5 seconds
var interval = Tick.helper.duration(5, 'seconds');
// value to add each interval
var valuePerInterval = 1;
// offset is a fixed date in the past
var dateOffset = Tick.helper.date('2021-04-19');
// value to start with, the value of the counter at the offset date
var valueOffset = 17143;
// start updating the counter each second
Tick.helper.interval(function () {
// current time in milliseconds
var now = Date.now();
// difference with offset time in milliseconds
var diff = now - dateOffset;
// total time since offset divide by interval gives us the amount of loops since offset
var loops = diff / interval;
// this will make sure we only count completed loops.
loops = Math.floor(loops);
// multiply that by the value per interval and you have your final value
tick.value = valueOffset + (loops * valuePerInterval);
}, 1000);
}
帮助 !
解决方案
推荐阅读
- javascript - 意外的令牌'<'错误(npx create-react-app)
- vhdl - 警告 (10631):VHDL 过程语句警告:推断信号或变量的锁存器
- vim - 用 vim 预览文件
- ios - 尝试连接到 Azure SQL Server Db 时,在应用审阅期间 Apple 应用审阅者的设备上出现错误
- python - 如何跟踪值在烧瓶应用程序的整个生命周期中不断变化的变量?
- tensorflow - What should I add so that when the system detects some specific object it will play an alert sound?
- android-studio - failed linking references - android studio
- javascript - 如何获取具有特定样式属性值的循环中元素的长度
- java - Strange print behavior using Unicode symbols in Eclipse (Java)
- bash - Replacing in place only on specific column using bash