我有一个关于免费插件的问题 http://ionden.com/a/plugins/ion.sound/en.html
我当前的javascript代码看起来像这样
(function ($) {
if($.ionSound) {
return;
}
var settings = {},
soundsNum,
canMp3,
url,
i,
sounds = {},
playing = false;
var createSound = function(name){
sounds[name] = new Audio();
canMp3 = sounds[name].canPlayType("audio/mp3");
if(canMp3 === "probably" || canMp3 === "maybe") {
url = settings.path + name + ".mp3";
} else {
url = settings.path + name + ".ogg";
}
$(sounds[name]).prop("src", url);
sounds[name].load();
sounds[name].volume = settings.volume;
};
var playSound = function(name){
var $sound = sounds[name],
playingInt;
if(typeof $sound === "object" && $sound !== null) {
if(!settings.multiPlay && !playing) {
$sound.play();
playing = true;
playingInt = setInterval(function(){
if($sound.ended) {
clearInterval(playingInt);
playing = false;
}
}, 250);
} else if(settings.multiPlay) {
if($sound.ended) {
$sound.play();
} else {
try {
$sound.currentTime = 0;
} catch (e) {}
$sound.play();
}
}
}
};
$.ionSound = function(options){
settings = $.extend({
sounds: [
"water_droplet"
],
path: "static/sounds/",
multiPlay: true,
volume: "0.5"
}, options);
soundsNum = settings.sounds.length;
if(typeof Audio === "function" || typeof Audio === "object") {
for(i = 0; i < soundsNum; i += 1){
createSound(settings.sounds[i]);
}
}
$.ionSound.play = function(name) {
playSound(name);
};
};
$.ionSound.destroy = function() {
for(i = 0; i < soundsNum; i += 1){
sounds[settings.sounds[i]] = null;
}
soundsNum = 0;
$.ionSound.play = function(){};
};
}(jQuery的));
我的问题是声音触发慢(间隔响应)有人知道这可以设置/创建响应,如1秒或更长甚至即时点击按钮我需要其他如果用户点击加快声音是没有足够快的反应
答案 0 :(得分:2)
很难理解你的问题。你的意思是这个?
$("#myButton").on("click", function(){
setTimeout(function(){
$.ionSound.play("button_tiny");
}, 1000); // 1 second delay
});