0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

リロード毎にランダムな音の再生

Last updated at Posted at 2021-02-16
main.html
		<div class="audio_wrap">
			<div class="audio_button "></div>
			<audio id="audio" class="js-random" loop id="sound" preload="auto">
			</audio>
		</div>
main.js
$(function () {
	var sorce = [
	'<source src="sound/A.mp3" type="audio/mp3">',
	'<source src="sound/B.mp3" type="audio/mp3">',
	'<source src="sound/C.mp3" type="audio/mp3">'
	];
	var randomList = Math.floor(Math.random() * sorce.length);
	console.log( randomList );
	$('.js-random').append(sorce[randomList]);
  });

ちなみに、コンソールエラーで
Uncaught SyntaxError: Invalid or unexpected tokenが出たら、何かちっちゃなミスがあるよ、ってことです!今回は終わりかっこ忘れでずっと動かなかった

解決のお世話になったURL
https://progblog-web.com/700/
ありがとうございます!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?