1 回答
TA贡献1802条经验 获得超5个赞
我基于您的代码创建了一个小示例,其中包含进度条和非常基本的标题选择逻辑。我还修复了第一个播放动作和第一个标题问题。您可以参考 w3schools,在那里您可以找到更多事件和标记属性的示例。
var songs = ["https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-4.mp3", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-5.mp3", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-6.mp3", "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-7.mp3"];
var poster = ["/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png", "/images/J&G Logo.png"];
var titles = ["I'm On My Way", "Rolling In The Deep", "Mad World", "Too Close", "Feelin' Good", "I Will Wait", "All These Things That I've Done"]
var songTitle = document.getElementById("songTitle");
var fillBar = document.getElementById("fill");
var song = new Audio();
var currentSong = 0;
songTitle.textContent = titles[currentSong];
function playSong(){
song.src = songs[currentSong];
songTitle.textContent = titles[currentSong];
song.play();
}
function playOrPauseSong(){
if(song.paused){
playSong();
$("#play img").attr("src","/images/Pause.png");
}
else{
song.pause();
$("#play img").attr("src","/Images/Play.png");
}
}
song.addEventListener('timeupdate',function(){
$('#seekbar').attr("value", this.currentTime / this.duration);
});
function next(){
currentSong++;
if(currentSong > songs.length - 1){
currentSong = 0;
}
playSong();
$("#play img").attr("src","/images/Pause.png");
$("#image img").attr("src",poster[currentSong]);
$("#bg img").attr("src",poster[currentSong]);
}
function pre(){
currentSong--;
if(currentSong < 0){
currentSong = songs.length - 1;
}
playSong();
$("#play img").attr("src","/images/Pause.png");
$("#image img").attr("src",poster[currentSong]);
$("#bg img").attr("src",poster[currentSong]);
}
function countProgress(event) {
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</audio>
<header id="about">
<div class="menu">
<span class="bar"></span>
</div>
<nav class="nav">
<div class="overlay">
<ul>
<li><a href="index.html">Home</a> </li>
<li><a class=active href="Album.html">Album</a> </li>
<li><a href="Gallery.html">Gallery</a> </li>
<li><a href="Book.html">Book Us</a> </li>
</ul>
</div>
</nav>
<div id="main">
<div id="image">
<img src="/images/J&G Logo.png"/>
</div>
<div id="player">
<div output id="songTitle"></div>
<div id="buttons">
<button id="pre" onclick="pre()"><img src="/images/backwards.png"></button>
<button id="play" onclick="playOrPauseSong()"><img src="/images/play.png"></button>
<button id="next" onclick="next()"><img src="/images/forwards.png"></button>
</div>
</div>
<progress id="seekbar" value="0" max="1" style="width:200px;"></progress>
</div>
添加回答
举报