我怎样才能用jQuery制作节拍器

时间:2011-02-16 12:36:41

标签: jquery performance tempo adjustable

这不一定是咔哒声。 我需要一些东西来想象某个节奏/节拍器

如何使声音或图像以某种节奏出现? 所以也许可以使用淡入淡出或切换()然后使用速度,你可以 在输入字段中调整。

有什么想法吗?

2 个答案:

答案 0 :(得分:3)

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());
});

答案 1 :(得分:1)

我猜你应该看看一些动画扩展和参数以便缓和。 你可以从这里开始http://api.jquery.com/animate/ 也许你可以从这个例子中获取一些代码:http://www.irengba.com/codewell/loop.html

相关问题