오디오에 타이머 붙이기
https://sir.kr/g5_tip/18697 의 연속팁입니다.
span 의 위치와 css 는 알아서...
차례대로 재생시간, 토탈시간, 남은시간의 순입니다.
쓰고 싶지 않은 span, 예를 들어서 남은시간 타이머가 필요 없으면
restTimer 이라는 span 을 삭제해 버리면 되겠습니다.
이것이 가능한 이유는 아래의 형식으로 이프문을 걸어주었기 때문입니다.
if (typeof restTimer != "undefined") --- 만일 restTimer 가 존재한다면
[code]
<audio id=myAudio src="https://blog.kakaocdn.net/dn/c4djm7/btrET8xkkOc/89VxkXWg4wSOrnwWPKsJqK/tfile.mp3" loop></audio>
<img id=myImg style=cursor:pointer;display:block>
<span id=currentTimer>00:00</span>
<span id=totalTimer>00:00</span>
<span id=restTimer>00:00</span>
<script>
onImg = "https://blog.kakaocdn.net/dn/wZ0tS/btrEOGJvjIE/8dv2ALyvIwk7cGS4p1Pkd0/img.png";
offImg = "https://blog.kakaocdn.net/dn/qrTkp/btrEN9SGsPz/0ztiKLUfAkLnmJON7nwc91/img.png";
function playAudio() {
myImg.src = offImg;
myAudio.play();
}
function pauseAudio() {
myImg.src = onImg;
myAudio.pause();
}
myImg.onclick = function() {
myAudio.paused ? playAudio() : pauseAudio();
}
myImg.src = onImg;
function trackMode() {
if (myAudio.currentTime > 0) {
if (typeof currentTimer != "undefined") currentTimer.innerText = ("0" + Math.floor(myAudio.currentTime / 60)).slice(-2) + ":" + ("0" + Math.floor(myAudio.currentTime % 60)).slice(-2);
if (typeof totalTimer != "undefined") totalTimer.innerText = ("0" + Math.floor(myAudio.duration / 60)).slice(-2) + ":" + ("0" + Math.floor(myAudio.duration % 60)).slice(-2);
if (typeof restTimer != "undefined") restTimer.innerText = ("0" + Math.floor((myAudio.duration - myAudio.currentTime) / 60)).slice(-2) + ":" + ("0" + Math.floor((myAudio.duration - myAudio.currentTime) % 60)).slice(-2);
}
}
setInterval(trackMode, 500);
</script>
[/code]
댓글 6개
리자님 레이다망에 안 걸릴 지 모르겠네요.ㅜㅠ
따지고 보면 그누팁이라기 보다는 일반팁이라서요.
트랙바까지만 올릴 생각입니다.ㅋ
초보자들은 게시판에 적용하기가 어려울수도 있어서 게시판에 적용해보았습니다.
https://sir.kr/g5_tip/18802
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4402 | ||
| 2514 | 1년 전 | 902 | ||
| 2513 |
베리소프트
|
1년 전 | 619 | |
| 2512 |
|
1년 전 | 949 | |
| 2511 |
|
1년 전 | 1078 | |
| 2510 | 1년 전 | 1006 | ||
| 2509 | 1년 전 | 1057 | ||
| 2508 | 1년 전 | 1308 | ||
| 2507 | 1년 전 | 686 | ||
| 2506 | 1년 전 | 1253 | ||
| 2505 |
|
1년 전 | 1207 | |
| 2504 | 1년 전 | 1407 | ||
| 2503 | 1년 전 | 944 | ||
| 2502 | 1년 전 | 1070 | ||
| 2501 | 1년 전 | 1169 | ||
| 2500 |
welcome
|
1년 전 | 1077 | |
| 2499 |
하늘그루터기
|
1년 전 | 870 | |
| 2498 | 1년 전 | 1177 | ||
| 2497 | 1년 전 | 645 | ||
| 2496 | 1년 전 | 963 | ||
| 2495 |
|
1년 전 | 1417 | |
| 2494 | 1년 전 | 944 | ||
| 2493 | 1년 전 | 946 | ||
| 2492 | 1년 전 | 1155 | ||
| 2491 | 1년 전 | 1120 | ||
| 2490 | 1년 전 | 1089 | ||
| 2489 | 1년 전 | 1019 | ||
| 2488 | 1년 전 | 772 | ||
| 2487 |
|
1년 전 | 1209 | |
| 2486 | 1년 전 | 830 | ||
| 2485 | 1년 전 | 1006 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기