好的,基本上,我想创建一个按钮来触发一个新的 javascript 函数。我希望按钮单击并保持单击状态(然后再次单击以关闭)。
我的代码(没有按钮):
function playSound(target) {
//Play the sound: play (src, interrupt, delay, offset, loop, volume, pan)
var instance = createjs.Sound.play(target.id, createjs.Sound.INTERRUPT_ANY, 0, 0, false, 1);
if (instance == null || instance.playState == createjs.Sound.PLAY_FAILED) { return; }
target.className = "gridBox1 active";
instance.addEventListener ("complete", function(instance) {
target.className = "gridBox1";
});
}
我想要一个可点击的按钮来触发一组新的循环声音,这就是我想出的:
<button id="buttonEv" onclick="myFunction()">Evolve</button>
<script>
function myFunction() {
function playSound(target) {
//Play the sound: play (src, interrupt, delay, offset, loop, volume, pan)
var instance = createjs.Sound.play(1, {loop:2});
instance.on("loop", handleLoop);
if (instance == null || instance.playState == createjs.Sound.PLAY_FAILED) { return; }
target.className = "gridBox1 active";
instance.addEventListener ("complete", function(instance) {
target.className = "gridBox1";
});
}
}
$('#buttonEv').click(function(event){
if($(this).hasClass('active')){
$(this).removeClass('active')
} else {
$(this).addClass('active')
}
});
</script>
按钮单击并保持单击状态,但不影响声音
说得通?有任何想法吗?谢谢!