Created
February 17, 2021 06:54
-
-
Save SeePetulaCode/bd3fb3b21eb58d5eeb52d66166f53a70 to your computer and use it in GitHub Desktop.
Click Image, Play Sound
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<audio id="myAudio" onended="audioEnds()"> | |
<source src="https://res.cloudinary.com/b1917/video/upload/v1613544387/codepen001/kid_laugh.mp3" type="audio/mpeg"> | |
Your browser does not support the audio element. | |
</audio> | |
<div id='playbutton' onclick="thisPlayer()" type="button"> | |
<img src='https://assets.codepen.io/1312923/Play_dark+backg%402x.png?format=auto' id='image'> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let x = document.getElementById("myAudio"); | |
let imgChange = document.getElementById("image"); | |
function playAudio() { | |
x.play(); | |
imgChange.src = "https://assets.codepen.io/1312923/Pause_dark+backg%402x.png"; | |
} | |
function pauseAudio() { | |
x.pause(); | |
x.currentTime = 0; | |
imgChange.src = "https://assets.codepen.io/1312923/Play_dark+backg%402x.png"; | |
} | |
function thisPlayer() { | |
x.play(); | |
imgChange.src = "https://assets.codepen.io/1312923/Pause_dark+backg%402x.png"; | |
} | |
function audioEnds() { | |
imgChange.src = "https://assets.codepen.io/1312923/Play_dark+backg%402x.png"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body{ | |
background-color: #ae638e; | |
} | |
#playbutton { | |
margin: 10% 50%; | |
} | |
img { | |
width: 200px; | |
margin: auto; | |
} | |
img:hover { | |
cursor: pointer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment