1
0
Fork 0

rewrite js

This commit is contained in:
Rhiannon Morris 2021-06-07 23:44:46 +02:00
parent 2996642ee5
commit f0ef814c1a
1 changed files with 13 additions and 8 deletions

View File

@ -88,22 +88,27 @@
</section>
</main>
<script>
window.addEventListener('DOMContentLoaded', () => {
window.addEventListener('DOMContentLoaded', function() {
let link = document.getElementById('soundlink');
let miku = document.getElementById('miku');
if (typeof miku.play == 'function') {
function playMiku(e) {
miku.play();
e.preventDefault();
}
link.href = '#';
link.addEventListener('click', playMiku);
function play(e) {
e.preventDefault();
miku.play();
}
// attempt to ensure at least one of the sources is recognised
// (and that <audio> is supported)
if (!isNaN(miku.duration)) {
link.href = '#listen';
link.addEventListener('click', play);
}
});
</script>
<!--
- mutant standard emoji by @Dzuque: 👉 https://mutant.tech 👈
(licensed cc-by-nc-sa 4.0)