0-1前端本地网页音乐播放器思路

前提准备

工具:
webstorm jQuery库 jQuery custom scrollbar插件

知识:
html,css,js,jQuery,jQuery custom scrollbar文档,ajax本地请求

作品名称:
前端网页音乐播放器(本地)

实现成果:
在这里插入图片描述

css,html

编写过程:
建文件夹、css、js、素材、连接库与相互连接到html中
在这里插入图片描述
在这里插入图片描述
主要点:
html写元素布局,hover实现悬停高亮, css渲染与定位(相对与绝对)
/
/
html:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
html实现后效果
在这里插入图片描述
css:

*{
    margin: 0;
    padding: 0;
}
html,body{
    width: 100%;
    height: 100%;
    font-size: 14px;
}
.header{
    width: 100%;
    height: 45px;
}
.header .logo{
    float: left;
    margin-left: 20px;
    opacity: 0.5;
}
.header .logo:hover{
    opacity: 1;
}
.header .logo a{
    display: inline-block;
    width: 78px;
    height: 21px;
    background: url("../images/player_logo.png") no-repeat 0 0;
}
.header .register{
    float: right;
    line-height: 45px;
}

.header .register li{
    list-style: none;
    float: left;
    margin-right: 20px;
    color: #fff;
    opacity: 0.5;
}
.header .register li:hover{
    opacity: 1;
}
.content{
    width: 100%;
    height: 460px;
}
.content .content_in{
    width: 1200px;
    height: 100%;
    margin: 0 auto;
}
.content_in .content_left{
    float: left;
    width: 800px;
    height: 100%;
}
.content_left .content_toolbar{
    width: 100%;
    height: 40px;
}
.content_toolbar span{
    display: inline-block;
    width: 122px;
    height: 100%;
    line-height: 40px;
    text-align: center;
    border: 1px solid #fff;
    box-sizing: border-box;
    border-radius: 5px;
    color: #fff;
    opacity: 0.5;
}
.content_toolbar span:hover{
    opacity: 1;
}
.content_toolbar span i{
    display: inline-block;
    width: 18px;
    height: 18px;
    background: url("../images/icon_sprite.png") no-repeat 0 0;
    margin-right: 10px;
    vertical-align: -5px;
}
.content_toolbar span:nth-child(1) i{
    background-position: -60px -20px;
}
.content_toolbar span:nth-child(2) i{
    background-position: -20px -20px;
}
.content_toolbar span:nth-child(3) i{
    background-position: -40px -240px;
}
.content_toolbar span:nth-child(4) i{
    background-position: -100px -20px;
}
.content_toolbar span:nth-child(5) i{
    background-position: -40px -300px;
}
.content_left .content_list{
    width: 100%;
    height: 420px;
    overflow: auto;
}
.content_list li{
    list-style: none;
    width: 100%;
    height: 50px;
    border-bottom: 1px solid rgba(255,255,255,0.5);
    box-sizing: border-box;
    user-select: none;
}
.content_list li div{
    float: left;
    color: rgba(255,255,255,0.5);
    line-height: 50px;
    /*opacity: 0.5;*/
}
.content_list .list_check{
    width: 50px;
    height: 100%;
    text-align: center;
}
.content_list .list_check i{
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 1px solid #fff;
    opacity: 0.5;
}
.content_list .list_checked i{
    background: url("../images/icon_sprite.png") no-repeat -60px -80px;
    opacity: 1;
}
.content_list .list_number{
    width: 20px;
    height: 100%;
}
.content_list .list_number2{
    color: transparent !important;
    background: url("../images/wave.gif") no-repeat 0 center;
}
.content_list .list_name{
    width: 50%;
    height: 100%;
}
.list_name .list_menu{
    margin-top: 5px;
    float: right;
    margin-right: 20px;
    display: none;
}
.list_menu a{
    display: inline-block;
    width: 36px;
    height: 36px;
    background: url("../images/icon_list_menu.png") no-repeat 0 0;
    opacity: 0.5;
}
.list_menu a:hover{
    opacity: 1;
}
.list_menu a:nth-child(1){
    background-position: -120px 0;
}
.list_menu a:nth-child(2){
    background-position: -120px -80px;
}
.list_menu a:nth-child(3){
    background-position: -120px -120px;
}
.list_menu a:nth-child(4){
    background-position: -120px -40px;
}

.list_menu .list_menu_play2{
    background-position: -80px -200px !important;
}
.content_list .list_singer{
    width: 20%;
    height: 100%;
}
.content_list .list_time a{
    display: inline-block;
    width: 36px;
    height: 36px;
    background: url("../images/icon_list_menu.png") no-repeat -120px -160px;
    float: left;
    margin-top: 5px;
    display: none;
    opacity: 0.5;
}
.content_list .list_time a:hover{
    opacity: 1;
}
.content_in .content_right{
    float: right;
    width: 400px;
    height: 100%;
    user-select: none;
}
.content_right .song_info{
    text-align: center;
    color: rgba(255,255,255,0.5);
    line-height: 30px;
}
.song_info .song_info_pic{
    display: inline-block;
    /*右侧渲染图片*/
    background: url("../images/album_cover_player.png") no-repeat 0 0;
    width: 201px;
    height: 180px;
    text-align: left;
}
.song_info_pic img{
    width: 180px;
    height: 180px;
}
.song_info div a{
    text-decoration: none;
    color: #fff;
    opacity: 0.5;
}
.song_info div a:hover{
    opacity: 1;
}
.content_right .song_lyric_container{
    margin-top: 30px;
    height: 150px;
    overflow: hidden;
}
.content_right .song_lyric{
    text-align: center;
}
.content_right .song_lyric li{
    list-style: none;
    line-height: 30px;
    font-weight: bold;
    color: rgba(255,255,255,0.5);
}
.content_right .song_lyric .cur{
    color: #31c27c;
}

.footer{
    width: 100%;
    height: 80px;
    position: absolute;
    left: 0;
    bottom: 0;
}
.footer .footer_in{
    width: 1200px;
    height: 100%;
    margin: 0 auto;
    user-select: none;
}
.footer_in a{
    display: inline-block;
    text-decoration: none;
    color: #fff;
    background: url("../images/player.png") no-repeat 0 0;
    margin-right: 20px;
}
.footer_in .music_pre{
    width: 19px;
    height: 20px;
    background-position: 0 -30px;
}
.footer_in .music_play{
    width: 21px;
    height: 29px;
    background-position: 0 0;
    vertical-align: -5px;
}
.footer_in .music_play2{
    background-position: -30px 0;
}
.footer_in .music_next{
    width: 19px;
    height: 20px;
    background-position: 0 -52px;
}
.footer_in .music_progress_info{
    display: inline-block;
    width: 670px;
    height: 40px;
    position: relative;
    top: 10px;
}
.music_progress_info .music_progress_top{
    width: 100%;
    height: 30px;
    line-height: 30px;
    color: #fff;
}
.music_progress_top .music_progress_name{
    float: left;
    opacity: 0.5;
}
.music_progress_top .music_progress_name:hover{
    opacity: 1;
}
.music_progress_top .music_progress_time{
    float: right;
    opacity: 0.5;
}
.music_progress_info .music_progress_bar{
    width: 100%;
    height: 4px;
    background: rgba(255,255,255,0.5);
    margin-top: 5px;
    position: relative;
}
.music_progress_bar .music_progress_line{
    width: 0px;
    height: 100%;
    background: #fff;
}
.music_progress_line .music_progress_dot{
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    position: absolute;
    top: -5px;
    left: 0px;
}
.footer_in .music_mode{
    width: 26px;
    height: 25px;
    background-position: 0 -205px;
}
.footer_in .music_mode2{
    width: 23px;
    height: 20px;
    background-position: 0 -260px;
}
.footer_in .music_mode3{
    width: 25px;
    height: 19px;
    background-position: 0 -74px;
}
.footer_in .music_mode4{
    width: 26px;
    height: 25px;
    background-position: 0 -232px
}
.footer_in .music_fav{
    width: 24px;
    height: 21px;
    background-position: 0 -96px;
}
.footer_in .music_fav2{
    background-position: -30px -96px;
}
.footer_in .music_down{
    width: 22px;
    height: 21px;
    background-position: 0 -120px;
}
.footer_in .music_comment{
    width: 24px;
    height: 24px;
    background-position: 0 -400px;
}
.footer_in .music_only{
    width: 74px;
    height: 27px;
    background-position: 0 -281px;
}
.footer_in .music_only2{
    background-position: 0 -310px;
}
.footer_in .music_voice_info{
    display: inline-block;
    width: 100px;
    height: 40px;'
line-height: 40px;
    position: relative;
    top: 10px;
}
.music_voice_info .music_voice_icon{
    width: 26px;
    height: 21px;
    background-position: 0 -144px;
    position: absolute;
    left: 0;
    top: 10px;
}
.music_voice_info .music_voice_icon2{
    background-position: 0 -182px;
}
.music_voice_info .music_voice_bar{
    width: 70px;
    height: 4px;
    background: rgba(255,255,255,0.5);
    position: absolute;
    right: 0;
    top: 18px;
}
.music_voice_bar .music_voice_line{
    width: 70px;
    height: 100%;
    background: #fff;
}
.music_voice_line .music_voice_dot{
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    position: relative;
    top: -5px;
    left: 70px;
}
.mask_bg{
    position: absolute;
    left: 0;
    top: 0;
    z-index: -2;
    width: 100%;
    height: 100%;
    background: url("../images/lnj.jpg") no-repeat 0 0;
    background-size: cover;
    filter: blur(100px);
}
.mask{
    position: absolute;
    left: 0;
    top: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.35);
}
._mCS_1 .mCSB_scrollTools .mCSB_dragger_bar{
    width:8px;
}

css实现后效果
在这里插入图片描述

js

js歌曲列表读入功能实现:
主要点:
先利用html,css布局基本list,再使用custom scrollbar插件导入
列表再用ajax本地请求导入
js:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

js实现后
在这里插入图片描述
歌曲栏,鼠标悬停特效功能:

hover本质mousenter悬停高亮,js的淡入淡出事件
动态添加的用事件委托delegate(如content_list下的list_meau等)

css
在这里插入图片描述
js:
在这里插入图片描述
在这里插入图片描述
css,js实现后效果
在这里插入图片描述

播放按钮,同步功能
主要点:事件委托,动态添加
在这里插入图片描述
在这里插入图片描述
播放和序号动画切换功能:
主要点:排它,切换类
在这里插入图片描述
在这里插入图片描述
播放功能(便于维护,单独工具类封装)
思路:
在这里插入图片描述
js:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

底部上首下首播放功能:
主要点:封装到player,js调用
在这里插入图片描述
在这里插入图片描述
删除后序列重新排序功能(防止重新排序bug):
主要点分情况,删除正在播放的,删除播放前面的,删除播放后面的
js:
在这里插入图片描述
在这里插入图片描述
点击切换歌词信息,背景功能:
未使用AJAX网络请求,本地json切换
js
在这里插入图片描述
在这里插入图片描述

进度条功能:(单独封装,便于维护与复用)
在这里插入图片描述
js(单独封装的js-player):在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
时间同步功能:
主要点:audio默认属性
在这里插入图片描述
在这里插入图片描述
js代码直接调用封装的js-player
在这里插入图片描述

进度条同步功能:
在这里插入图片描述
在这里插入图片描述
歌曲同步功能:
主要点bug1:进度条回弹
bug2:进度条拖拽,歌曲播放不流畅效果

在这里插入图片描述
在这里插入图片描述
通过回调函数,调用

音乐声音控制:
js:
在这里插入图片描述
在这里插入图片描述

js-player
在这里插入图片描述

bug1:
在这里插入图片描述
解决
在这里插入图片描述
bug2:进度条超过范围
在这里插入图片描述
解决2:(判断是否合法)
在这里插入图片描述
歌词同步功能:
主要点:歌词解析
歌词同步

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述


  • 5
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
基于网页的个性化音乐播放器可以根据用户的喜好和历史播放记录来推荐歌曲,同时提供基本的音乐播放器功能。以下是实现功能的一些步骤: 1. 使用HTML5和CSS3技术创建一个黑色质感的音乐播放器界面。 ```html <div class="music-player"> <div class="player-controls"> <button class="play-button"></button> <button class="pause-button"></button> <button class="next-button"></button> <button class="previous-button"></button> </div> <div class="song-info"> <div class="song-title"></div> <div class="song-artist"></div> </div> <div class="progress-bar"> <div class="progress"></div> </div> </div> ``` 2. 使用JavaScript编写音乐播放器的逻辑,包括播放、暂停、下一首、上一首等功能。 ```javascript var audio = new Audio(); var playlist = [ {title: 'Song 1', artist: 'Artist 1', file: 'song1.mp3'}, {title: 'Song 2', artist: 'Artist 2', file: 'song2.mp3'}, {title: 'Song 3', artist: 'Artist 3', file: 'song3.mp3'} ]; var currentSongIndex = 0; function playSong() { audio.src = playlist[currentSongIndex].file; audio.play(); updateSongInfo(); } function pauseSong() { audio.pause(); } function nextSong() { currentSongIndex = (currentSongIndex + 1) % playlist.length; playSong(); } function previousSong() { currentSongIndex = (currentSongIndex - 1 + playlist.length) % playlist.length; playSong(); } function updateSongInfo() { var titleElement = document.querySelector('.song-title'); var artistElement = document.querySelector('.song-artist'); titleElement.textContent = playlist[currentSongIndex].title; artistElement.textContent = playlist[currentSongIndex].artist; } audio.addEventListener('ended', nextSong); ``` 3. 使用AJAX技术从服务器获取用户的历史播放记录和喜好,根据这些信息推荐歌曲。 ```javascript function getRecommendations() { var xhr = new XMLHttpRequest(); xhr.open('GET', '/recommendations'); xhr.onload = function() { if (xhr.status === 200) { var recommendations = JSON.parse(xhr.responseText); playlist = recommendations; currentSongIndex = 0; playSong(); } }; xhr.send(); } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值