gpt4 book ai didi

javascript - 向 slider 添加声音

转载 作者:行者123 更新时间:2023-11-30 18:13:04 25 4
gpt4 key购买 nike

我有 13 张照片,我会将它们放入一个 slider 中。我想为每个图像附加一个声音,例如,当我到达图像 10 时,声音 10 开始播放。

我是 jQuery 的新手,我考虑过使用 Orbit作为 slider ,但我不知道如何将声音集成到其中。

有什么简单的想法可以做到这一点吗?

最佳答案

如果您不需要旧版浏览器支持,请查看 Web Audio API。 https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html

这是一个例子:http://www.html5rocks.com/en/tutorials/webaudio/intro/

//call the init function on window load
window.onload = init;
var context;
var bufferLoader;
//create 2 audio sources... as there were 2 in the example linked above
var source1 = context.createBufferSource();
var source2 = context.createBufferSource();

function init() {
//initialise the audio context
context = new webkitAudioContext();

//init preloading of sounds
bufferLoader = new BufferLoader(
context,
[
'../sounds/br-jam-loop.wav',
'../sounds/laughter.wav',
],
finishedLoading // <- callback function when finished loading
);

bufferLoader.load();
}

function finishedLoading(bufferList) {
//set the buffers of the sources from the loaded bufferlist
source1.buffer = bufferList[0];
source2.buffer = bufferList[1];

//connect the sources to the output
source1.connect(context.destination);
source2.connect(context.destination);
}

然后您可以使用您的插件回调函数之一来触发声音,如:

$('#featured').orbit({
afterSlideChange: function(){
source1.noteOn(0);
source2.noteOn(0);
}
});

类似的东西应该可以解决问题。

...还有一些框架可以为您完成一些工作。 http://www.schillmania.com/projects/soundmanager2/是一个很好的。

关于javascript - 向 slider 添加声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14104848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com