[英]I have an option form and I would like to show a different image from a JSON file for each element of the option tag i choose
[英]With an array of pictures I would like to have a different audio for each image
我已经建立了一张随机的幻灯片,可以播放许多图片。 我想为每个片段添加一个简短的音频剪辑,并使它们与我用于随机图片的数组同步。 以下是我所拥有的类似示例。 我是JavaScript的新手,我已经在数百个地方搜索了答案,但似乎没有任何效果。 请帮忙。 谢谢。
UPDATE。 我可能不清楚。 这就是我想要做的:我的儿子爱动物。 他自闭症,所以他不断地列出自己的动物及其有关的事物。 我为他的计算机创建了一个幻灯片演示,其中包含所有500张图片及其相关内容。 它会在一个屏幕上自动播放随机图像,而他可以在另一个屏幕上手动浏览。 他想用他们的名字和关于他们的东西录制5-10秒的短音频。 我希望能够将他的录音与图片关联起来,并在每次图像更改时播放录音
addImages = new Array
addImages[0] = "one.bmp"
addImages[1] = "two.bmp"
addImages[2] = "three.bmp"
addImages[3] = "four.bmp"
addImages[4] = "five.bmp"
addImages[5] = "six.bmp"
addImages[6] = "seven.bmp"
imgCt = addImages.length
firstTime = true
addSound = new Array
addSound[0] = "tada.wav"
addSound[1] = "recycle.wav"
addSound[2] = "ringout.wav"
addSound[3] = "notify.wav"
addSound[4] = "tada.wav"
addSound[5] = "tada.wav"
addSound[6] = "tada.wav"
imgCt2 = addSound.length
function rotate()
{
if (document.images)
{
if (firstTime)
{
thisAdd = Math.floor((Math.random() * imgCt))
firstTime = false
}
else
{
thisAdd++
if (thisAdd == imgCt)
{
thisAdd = 0
}
}
document.myPicture.src=addImages[thisAdd]
setTimeout("rotate()", 3 * 1000)
}
}
您没有正确添加到数组。 创建一个数组,然后继续覆盖它; 不用一遍又一遍地设置变量,而使用push()
addImages = new Array
addImages.push(["one.bmp", "tada.wav"])
addImages.push(["two.bmp", "tada.wav"])
addImages.push(["three.bmp", "tada.wav"])
addImages.push(["four.bmp", "tada.wav"])
addImages.push(["five.bmp", "tada.wav"])
addImages.push(["six.bmp", "tada.wav"])
addImages.push(["seven.bmp", "tada.wav"])
要获取图像,请执行addImages[i][0]
,要获取图像,请执行addImages[i][1]
。 无需像您以后那样为声音创建单独的数组。
谢谢大家的帮助。 我能够提出一个答案。
<script>
function pickimg() {
var imagenumber = 4;
var randomnumber = Math.random();
var rand1 = Math.round((imagenumber - 1) * randomnumber) + 1;
images = new Array
images[1] = "image1.bmp"
images[2] = "image2.bmp"
images[3] = "image3.bmp"
images[4] = "image4.bmp"
var image = images[rand1];
document.randimg.src = image
var sounds = new Array
sounds[1] = "sound1.wav"
sounds[2] = "sound2.wav"
sounds[3] = "sound3.wav"
sounds[4] = "sound4.wav"
var sound = sounds[rand1];
audioTag.src = sound;
audioTag.play();
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.