-
-
Save GeorgianStan/8b227b6bba790d4c681f48e6e7b7c147 to your computer and use it in GitHub Desktop.
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
const _setAudioTime = (e, line) => { | |
let offset = 15, //15 because has a padding left of 15 px | |
clickedX = e.clientX - offset, | |
elementWidth = line.clientWidth, | |
percentClicked = clickedX * 100 / elementWidth, | |
audioDuration = _audioElem.duration; | |
let timeClicked = percentClicked * audioDuration / 100; | |
_audioCircle.style.left = percentClicked + '%'; | |
_audioElem.currentTime = timeClicked | |
_setFormatedTime(timeClicked, _songCurrentTimeLabel); | |
} | |
// set song duration when the audio element receive metadata | |
_audioElem.addEventListener('loadedmetadata', () => | |
_setFormatedTime(_audioElem.duration, _songDurationLabel) | |
); | |
--------------------------------------- | |
_audioLine.addEventListener('click', function (e) { | |
_setAudioTime(e, this) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment