我使用 map 坐标作为网站 Logo 的一部分。 (2.378628、48.853373)。
我想要做的是从 0.000000 开始计算两个数字,以便它们在同一时间(3-5 秒)内达到给定点,并递增 0.000001。这怎么可能?这会使我的计算机崩溃,并且 setInterval 每毫秒执行一次操作,这是不够的。
while (i < 48.853373) {
i = i + 0.000001;
$('.js-center-lat').text(i);
}
最佳答案
听起来您想要“动画” float 以计数到定义的值。 您是否考虑过第三方库,例如 CountUp.js ?
CountUp.js is a dependency-free, lightweight JavaScript "class" that can be used to quickly create animations that display numerical data in a more interesting way.
如何使用它的简单示例:
var options = {
useEasing: true,
useGrouping: true,
separator: '',
decimal: '.',
};
var demo = new CountUp('myTargetElement', 0, 2.415543, 6, 2.5, options);
if (!demo.error) {
demo.start();
} else {
console.error(demo.error);
}
希望这有帮助!
关于javascript - 如何在几秒钟内将数字从 00.000000 增加到 48.853373 0.00001,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54768427/