Skip to content

Instantly share code, notes, and snippets.

@GeorgianStan
Created March 9, 2020 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeorgianStan/8b227b6bba790d4c681f48e6e7b7c147 to your computer and use it in GitHub Desktop.
Save GeorgianStan/8b227b6bba790d4c681f48e6e7b7c147 to your computer and use it in GitHub Desktop.
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