jquery实现一个带歌曲列表的音乐播放器效果代码

代码语言:html

所属分类:多媒体

代码描述:jquery实现一个带歌曲列表的音乐播放器效果代码,可设置封面图片。

代码标签: 歌曲 列表 音乐 播放器 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">

<style>

body {
    margin: 0; padding: 0;
    background: #1d1d1d;
}

* {
    box-sizing: border-box;
}

h1, h2, h3,h4, h5, h6, p, ul, li {
    margin: 0; padding: 0;
}

li { list-style: none; }
@font-face {
    font-family: "iconfont";
    src: url('iconfont.eot?t=1537976418058');
    /* IE9*/
    src: url('iconfont.eot?t=1537976418058#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAAmcAAsAAAAADgwAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAADMAAABCsP6z7U9TLzIAAAE8AAAARAAAAFY8lGHxY21hcAAAAYAAAACUAAACBGvSDaxnbHlmAAACFAAABUMAAAbwatoOAWhlYWQAAAdYAAAALwAAADYSwtboaGhlYQAAB4gAAAAcAAAAJAfeA4tobXR4AAAHpAAAAA8AAAAoKAAAAGxvY2EAAAe0AAAAFgAAABYIpgZ4bWF4cAAAB8wAAAAdAAAAIAEYAGNuYW1lAAAH7AAAAUUAAAJtPlT+fXBvc3QAAAk0AAAAZQAAAJSspZ5ZeJxjYGRgYOBikGPQYWB0cfMJYeBgYGGAAJAMY05meiJQDMoDyrGAaQ4gZoOIAgCKIwNPAHicY2BkYWCcwMDKwMHUyXSGgYGhH0IzvmYwYuRgYGBiYGVmwAoC0lxTGByeyf3/z9zwv4EhhrmBoQEozAiSAwD0fA0ZeJztkcENwjAQBMdxCAQhQgU88qYeesBKGoh48aLSS7oIa1+QKIKzxtKedWdpF9gBUdxEDeFNINdL3VD6k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6OwAk4AtyAO/BIJ5s2lsffvHljTwDc4Acejt8t95E9XDI7cg0XuBeuU38QbpBfhJto41W4Rf1N2MczpsJtdGF5g9e4YvaEd2EPHXwI13CNT+E69S/hBvlbuIk7/Aq30PHqwj7mXle4jUcv9sdWL5xeqeVBxaHJIpM5v4KZXu+Sha3S6pxrW8QmU4OgX0lTnWlb3VPs10PnIhVZk6oJqzpJjMqt2erQBRvn8lGvF4kehCblWGP+tsYCjnEFhSUOjDFCGGSIyujoO1Vm9K+xQ8Jee1Y9zed0WxTU/3OFAQL0z1xTurLSeTpPgT1fG1J1dCtuy56UNJFezUkSskJe1rZUQuoBNmVXjhF6XNGJPyhnSP8ACVpuyAAAAHicbcrBCoNADATQjLau3dWPjBTdaInINqD9+gb06MBc3gxVdCbSfSIq1HjgiQYBLV6ISJRKZp0OKXm1sBjLLNoM6+gYfqxf0SkVc73MZ39r6/2IQ7+bZmM95+7NutlFRH+UdSMxAAAA') format('woff'), url('iconfont.ttf?t=1537976418058') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/ url('iconfont.svg?t=1537976418058#iconfont') format('svg');
    /* iOS 4.1- */
}

.iconfont {
    font-family: "iconfont" !important;
    font-size: 16px;
    font-style: normal;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.icon-prev:before {
    content: "\f0069";
}

.icon-next:before {
    content: "\f006a";
}

.icon-play:before {
    content: "\e66a";
}

.icon-pause:before {
    content: "\e76a";
}

.icon-random:before {
    content: "\e622";
}

.icon-muted:before {
    content: "\e61e";
}

.icon-volume:before {
    content: "\e87a";
}

.icon-loop:before {
    content: "\e66c";
}

.icon-single:before {
    content: "\e66d";
}

    /* 播放器大小 */
.music-player {
    width: 550px;
}

/* 播放器位置 */
.music-player {
    position: relative;
    margin: 200px auto;
}

/* 歌曲列表 */

.music-player__list {
    width: 100%;
    padding: 10px;
    margin-top: 50px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 5px;
    -webkit-box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.music__list__item {
    padding-left: 25px;
    color: #ccc;
    position: relative;
    margin-bottom: 10px;
    font-size: 14px;
    cursor: pointer;
}

.music__list__item:last-of-type {
    margin: 0;
}

.music__list__item.play {
    color: #fff;
}

.music__list__item.play:before {
    font-family: 'iconfont';
    content: "\e87a";
    position: absolute;
    left: 0px;
    top: 4px;
}


/* 播放器主体 */
.music-player__main {
    height: 180px;
    padding: 25px;
    -webkit-box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
    border-radius: 10px;
    position: relative;
    overflow: hidden;
}

/* 播放器主体模糊背景 */
.music-player__blur {
    width: 100%;
    height: 100%;
    position: absolute;
  
    background-size: 100%;
    left: 0;
    top: 0;
    z-index: -1;
    -webkit-filter: blur(20px);
    filter: blur(20px);
}



/* 播放器唱片效果 */
.music-player__disc {
    float: left;
    width: 130px;
    height: 130px;
    background: url(//repo.bfw.wiki/bfwrepo/images/music/cd.png) no-repeat center;
    background-size: 100%;
    position: relative;
}

/* 唱片指针 */
.music-player__pointer {
    width: 25px;
    position: absolute;
    right: -10px;
    top: 0;
    -webkit-transform-origin: right top;
    -ms-transform-origin: right top;
    transform-origin: right top;
    -webkit-transform: rotate(-15deg);
    -ms-transform: rotate(-15deg);
    transform: rotate(-15deg);
    -webkit-transition: all 0.3s;
    -o-transition: all 0.3s;
    transition: all 0.3s;
}

/* 唱片指针播放状态 加play类名 */
.music-player__pointer.play {
    -webkit-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    transform: rotate(0deg);
}

/* 唱片歌曲图片 */
.music-player__image {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    position: absolute;
    overflow: hidden;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
}


/* 播放器控件 */

.music-player__controls {
    width: 330px;
    height: 130px;
    float: right;
}

/* 歌曲信息 */
.music__info {
    width: 100%;
    height: 50px;
    margin-bottom: 15px;
}

.music__info .music__info--title,
.music__info .music__info--singer {
    color: #fff;
}

.music__info .music__info--title {
    font-size: 16px;
}

.music__info .music__info--singer {
    color: #ccc;
    font-size: 14px;
    margin-top: 10px;
}

/* 控件 */

.player-control {
    width: 100%;
}

.player-control__content {
    margin-bottom: 5px;
    overflow: hidden;
}

/* 播放暂停按钮 */
.player-control__btns {
    float: left;
    overflow: hidden;
}

.player-control__btn {
    float: left;
    margin: 0 5px;
    font-weight: bolder;
    color: #fff;
    cursor: pointer;
}

.player-control__volume {
    float: right;
    overflow: hidden;
}

.control__volume--progress {
    float: left;
    width: 100px;
    position: relative;
    top: 8px;
}

.player__song--timeProgess{
    font-size: 12px;
    color: #fff;
    margin-top: 5px;
    padding: 0px 3px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
}

.nowTime{
    float: left;
}
.totalTime{
    float: right;
}

.progress {
    background: rgba(0, 0, 0, 0.3);
    height: 5px;
    -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5) inset;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5) inset;
    overflow: hidden;
    border-radius: 2px;
    position: relative;
    cursor: pointer;
}

.progress .back {
    width: 0px;
    height: 100%;
    border-radius: 2px;
    background: rgb(12, 182, 212);
}

.progress .pointer {
    width: 7px;
    height: 7px;
    background: #fff;
    border-radius: 50%;
    opacity: 0;
    -webkit-transition: opacity 0.3s;
    -o-transition: opacity 0.3s;
    transition: opacity 0.3s;
    position: absolute;
    top: -1px;
    left: 0;
}

.progress:hover .pointer {
    opacity: 1;
}


/* 播放 画片 动画 */

@-webkit-keyframes disc {
    from {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
    }

    to {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
    }
}

@keyframes disc {
    from {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
    }

    to {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
    }
}

.music-player__image.play {
    -webkit-animation: disc 5s linear 0s infinite;
    animation: disc 5s linear 0s infinite;
}


/*  播放进度  */

.player__song--progress {
    width: 100%;
    margin-top: 15px;
}
</style>
</head>
<body>

<!-- 播放器 -->
<div class="music-player">
	<!-- audio标签 -->
	<audio class="music-player__audio" ></audio>
	<!-- 播放器主体 -->
	<div class="music-player__main">
		<!-- 模糊背景 -->
		<div class="music-player__blur"></div>
		<!-- 唱片 -->
		<div class="music-player__disc">
			<!-- 唱片图片 -->
			<div class="music-player__image">
				<img width="100%" src="" alt="">
			</div>
			<!-- 指针 -->
			<div class="music-player__pointer"><img width="100%" src="//repo.bfw.wiki/bfwrepo/images/music/cd_tou.png" alt=""></div>
		</div>
		<!-- 控件主体 -->
		<div class="music-player__controls">
			<!-- 歌曲信息 -->
			<div class="music__info">
				<h3 class="music__info--title">...</h3>
				<p class="music__info--singer">...</p>
			</div>
			<!-- 控件... -->
			<div class="player-control">
				<div class="player-control__content">
					<div class="player-control__btns">
						<div class="player-control__btn player-control__btn--prev"><i class="iconfont icon-prev"></i></div>
						<div class="player-control__btn player-control__btn--play"><i class="iconfont icon-play"></i></div>
						<div class="player-control__btn player-control__btn--next"><i class="iconfont icon-next"></i></div>
						<div class="player-control__btn player-control__btn--mode"><i class="iconfont icon-loop"></i></div>
					</div>
					<div class="player-control__volume">
						<div class="control__volume--icon player-control__btn"><i class="iconfont icon-volume"></i></div>
						<div class="control__volume--progress progress"></div>
					</div>
				</div>

				<!-- 歌曲播放进度 -->
				<div class="player-control__content">
					<div class="player__song--progress progress"></div>
					<div class="player__song--timeProgess nowTime">00:00</div>
					<div class="player__song--timeProgess totalTime">00:00</div>
				</div>

			</div>

		</div>
	</div>
	<!-- 歌曲列表 -->
	<div class="music-player__list">
		<ul class="music__list_content">
			<!-- <li class="music__list__item play">123</li>
			<li class="music__list__item">123</li>
			<li class="music__list__item">123</li> -->
		</ul>
	</div>
</div>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery.1.11.min.js"></script>
<script >
    class Util {
    constructor() {
        if (Util.instance) return Util.instance;
        return this.getInstance(...arguments);
    }

    getInstance() {
        var instance = {
            /*
             *   formatTime 格式化时间(s)为 hour:minutes:seconds
             *   @params  time  required number (s)
             *   
             *   return hour:minutes:seconds string
             */

            formatTime(time) {
                //没有传time的时候
                if (time === undefined) {
                    this.handlerError(123, {
                        method: 'formate',
                        param: 'time'
                    });
                    return false;
                }
                let _time = Math.floor(time);
                let _minutes = Math.floor(_time / 60);
                let _hours = Math.floor(_minutes / 60);
                let _seconds = _time - (_minutes * 60);

                return (_hours ? this.fillZero(_hours) + ':' : '') + this.fillZero(_minutes - (_hours * 60)) + ':' + this.fillZero(_seconds);
            },
            /*
             *   fillZero 为小于10的数字补0
             *   @params  num  required number
             *   return '01'.. string
             */
            fillZero(num) {
                //当没有传time的时候
                if (num === undefined) {
                    this.handlerError(123, {
                        method: 'fillZero',
                        param: 'num'
                    });
                    return false;
                }
                //这个函数只是让我们在渲染/显示的时候有一个不同的效果,不要操作原数据
                return num > 9 ? num : '0' + num;
            },
            errors: {
                123: ({
                    method,
                    param
                }) => {
                    return method + 'function need a param ' + param;
                }
            },
            handlerError(code, options) { //处理报错
                console.error('[unt.........完整代码请登录后点击上方下载按钮下载查看

网友评论0