jquery - 我如何用 jQuery 制作节拍器

标签 jquery performance tempo adjustable

这不必伴随着咔嗒声。 我需要一些东西来可视化特定的节奏/节拍器

如何让声音或图像以一定的节奏出现? 因此,也许可以使用 fadetoggle() 但然后使用您可以的节奏 在输入字段中进行调整。

有什么想法吗?

最佳答案

function metronomeTick() {
   $("#metronome").toggle();
   setTimeout("metronomeTick()", 1000*60/$("#bpm").val());
}

metronomeTick();

JavaScript setInterval() 方法通常不被鼓励,因为它没有记住函数的“执行时间”(例如,实际可视化刻度需要多长时间)。再想一想,在这种情况下 setInterval 会更好,因为它对时间要求很高。

使用setInterval(),代码将类似于:

var intervalReference = setInterval("metronomeTick()", 1000*60/$("#bpm").val());

function metronomeTick() {
  // Do tick visualisation here, but make sure it takes only a reasonable amount of time
  // Less than 1000*60/bpm, that is
}

$("#bpm").change(function() {
  clearInterval(intervalReference);
  intervalReference = setInterval("metronomeTick()", 1000*60/$(this).val());
});

关于jquery - 我如何用 jQuery 制作节拍器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5016480/

相关文章:

c - OpenCV FAST角点检测SSE实现演练

c# - 读取和处理每个约 100Mb 的大型文本文件

c# - 诊断 asp.net 网站/应用程序池的性能

javascript - 使用 Tempo 转换树结构

jquery - 在 jquery 中更改按钮标签内的跨度文本

在 Ruby On Rails 中使用幻灯片放映的 jQuery

javascript - 如何刷新 tempo js 以显示新数据?

c# - 使用声音文件 C# - 修改速度

javascript - Jquery - 查找已检查的 radio 并触发同级的点击

javascript - 具有单独操作值的 Ajax 表单