A Pen by Website Beaver on CodePen.
Created
December 9, 2019 18:17
-
-
Save alasomlira/95928a2aad457a8cc243e4a6905b455a to your computer and use it in GitHub Desktop.
html5 audio player only play button
This file contains hidden or 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
| <a id="play-pause-button" class="fa fa-play"></a> |
This file contains hidden or 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
| var audio = new Audio("http://www.stephaniequinn.com/Music/Allegro%20from%20Duet%20in%20C%20Major.mp3"); | |
| $('#play-pause-button').on("click",function(){ | |
| if($(this).hasClass('fa-play')) | |
| { | |
| $(this).removeClass('fa-play'); | |
| $(this).addClass('fa-pause'); | |
| audio.play(); | |
| } | |
| else | |
| { | |
| $(this).removeClass('fa-pause'); | |
| $(this).addClass('fa-play'); | |
| audio.pause(); | |
| } | |
| }); | |
| audio.onended = function() { | |
| $("#play-pause-button").removeClass('fa-pause'); | |
| $("#play-pause-button").addClass('fa-play'); | |
| }; |
This file contains hidden or 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
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script> |
This file contains hidden or 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
| #play-pause-button{ | |
| font-size: 50px; | |
| cursor: pointer; | |
| } |
This file contains hidden or 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
| <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment