Music Player with Javascript
Course from Brad Traversy
Features:
audio play() pause() currentTime duration timeupdate ended
e.target e.clentWidth e.offsetX
HTML
music-info includes a song title and the progress barthe cover image positions at the left side
CSS
The cover image has a white circle inside for good looking.animation-play-state:running/paused more info MDN
music-info hide behind the container first and transform up entirely, and also the opacity from 0 to 1
JS
select all the DOM neededWhen loading the page, load the song
if the audio is playing, pause the song. if the song is paused, play the song
pauseSong(): remove the class to the music container and change the icon of controls. pause() audio
nextSong():change the index of song. when the index is bigger than the length of songs list,jump to the first one.
click the progress bar to change the audio playing position
get the playing percentage of progress and set the width of progress
the length of progress is the e.clientWidth.the click point is the e.offset X. set the audio currentTime