js实现一个简洁的带列表的音乐播放器效果代码
代码语言:html
所属分类:多媒体
代码描述:js实现一个简洁的带列表的音乐播放器效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @import url('https://fonts.googleapis.com/css2?family=Quicksand:wght@700&display=swap'); html { box-sizing: border-box ; --parent-height : 20em ; --duration: 1s ; --duration-text-wrap: 12s 1.5s cubic-bezier(0.82, 0.82, 1, 1.01) ; --cubic-header: var(--duration) cubic-bezier(0.71, 0.21, 0.3, 0.95) ; --cubic-slider : var(--duration) cubic-bezier(0.4, 0, 0.2, 1) ; --cubic-play-list : .35s var(--duration) cubic-bezier(0, 0.85, 0.11, 1.64) ; --cubic-slider-context : cubic-bezier(1, -0.01, 1, 1.01) ; } html *, html *::before, html *::after { box-sizing: inherit ; } body{ margin: 0 ; height: 100vh ; display: flex ; user-select: none ; align-items: center ; justify-content: center ; background-color: #e5e7e9 ; font-family: 'Quicksand', sans-serif ; -webkit-tap-highlight-color: transparent ; transition: background-color var(--cubic-slider) ; } .img { width: 100% ; display: block ; object-fit: cover ; } .list { margin: 0 ; padding: 0 ; list-style-type: none ; } .flex { display: flex ; align-items: center ; justify-content: space-between ; } .uppercase{ text-transform: uppercase ; } .player { width: 17.15em ; display: flex ; overflow: hidden ; font-size: 1.22em ; border-radius: 1.35em ; flex-direction: column ; background-color: white ; height: var(--parent-height) ; } .player__header { z-index: 1 ; gap: 0 .4em ; width: 100% ; display: flex; height: 5.85em ; flex-shrink: 0 ; position: relative; align-items: flex-start ; border-radius: inherit ; justify-content: flex-end ; background-color: white ; padding: .95em 0.6em 0 1.2em ; box-shadow: 0 2px 6px 1px #0000001f ; transition: height var(--cubic-header), box-shadow var(--duration), padding var(--duration) ease-in-out ; } .player__header.open-header { height: 100% ; padding-left: 0 ; padding-right: 0 ; box-shadow: unset ; } .player__img { width: 3.2em ; height: 3.2em ; border-radius: 1.32em ; } .player__img--absolute { top: 1.4em ; left: 1.2em ; position: absolute ; } .slider { flex-shrink: 0 ; overflow: hidden ; transition: width var(--cubic-header), height var(--cubic-header), top var(--cubic-header), left var(--cubic-header); } .slider.open-slider{ top: 0 ; left: 0 ; width: 100% ; height: 14.6em ; } .slider__content { display: flex ; height: 100% ; transition: transform var(--cubic-slider); } .slider__img { filter: brightness(75%) ; } .slider__name, .slider__title { overflow: hidden ; white-space: nowrap ; } .text-wrap { display: block ; white-space: pre ; width: fit-content ; animation: text-wrap var(--duration-text-wrap) infinite ; } @keyframes text-wrap { 75%{ transform: translate3d(-51.5%, 0, 0) ; } 100%{ transform: translate3d(-51.5%, 0, 0) ; } } .player__button { all: unset ; z-index: 100 ; width: 2.5em ; height: 2.5em ; cursor: pointer ; } .playlist { transform: scale(0) ; transition: transform calc(var(--duration) / 2) ; } .slider.open-slider .playlist { transform: scale(1) ; transition: transform var(--cubic-play-list) ; } .player__button--absolute--nw { top: 5.5% ; left: 5.5% ; position: absolute ; } .player__button--absolute--center { top: 0 ; left: 0 ; right: 0 ; bottom: 0 ; margin: auto ; position: absolute ; } img[alt ="pause-icon"] { display: none ; } .player__controls { width: 77% ; gap: .5em 0 ; display: flex ; flex-wrap: wrap ; align-items: center ; will-change: contents ; align-content: center ; justify-content: center ; transition: transform var(--cubic-header) , width var(--cubic-header) ; } .player__controls.move { width: 88% ; transform: translate3d(-1.1em , calc(var(--parent-height) - 153%) , 0) ; } .player__context { margin: 0 ; width: 100% ; display: flex ; line-height: 1.8 ; flex-direction: column ; justify-content: center ; text-transform: capitalize ; } .slider__context { width: 56.28% ; cursor: pointer ; text-align: center ; padding-bottom: .2em ; will-change: contents ; transition: width var(--cubic-header) ; animation: calc(var(--duration) / 2) var(--cubic-slider-context) ; } @keyframes opacity { 0% { opacity: 0 ; } 90%{ opacity: 1 ; } } .player__controls.move .slider__context{ width: 49.48% ; } .player__title { font-size: .7em ; font-weight: bold ; color: #00000086 ; } .progres { width: 90% ; height: .25em ; cursor: pointer ; border-radius: 1em ; background-color: #e5e7ea ; transition: width var(--cubic-header) ; } .player__controls.move .progres{ width: 98% ; } .progres__filled { width: 0% ; height: 100% ; display: flex ; position: relative ; align-items: center ; border-radius: inherit ; background-color: #78adfe ; } .progres__filled::before { right: 0 ; width: .35em ; content: " " ; height: .35em ; border-radius: 50% ; position: absolute ; background-color: #5781bd ; } .player__playlist { height: 100% ; overflow: auto ; padding: 1.05em .9em 0 1.2em ; } .player__playlist::-webkit-scrollbar { width: 0 ; } .player__song { /* gap: 0 .65em ; */ display: flex ; cursor: pointer ; margin-bottom: .5em ; padding-bottom: .7em ; border-bottom: .1em solid #d8d8d859 ; } .player__song .player__context { line-height: 1.5 ; margin-left: .65em ; } .player__song-name { font-size: .88em ; } .player__song-time { font-size: .65em ; font-weight: bold ; color: #00000079 ; height: fit-content ; align-self: flex-end ; } .audio { display: none !important ; } </style> </head> <body> <div class="player"> <div class="player__header"> <div class="player__img player__img--absolute slider"> <button class="player__button player__button--absolute--nw playlist"> <img src="svg/playlist.svg" alt="playlist-icon"> </button> <button class="player__button player__button--absolute--center play"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAA/0lEQVRIS+2W4Q2CMBSE7ybQEdxER8ENdAPYADbQDXQCHUEnUDdwg5pLaGJMpKU8wETen/4o8L27Pg6IkYojcTGBB3P+t612zi0ALAEcST4tbAkqds7NAdwAaBU0J1l1hceAVwBOH6ALgDVJrUmVCvawEkCRYn9XsBq4A9iSPLSRbgH2vHNtvxoJliVYMA1fSbIIka3Bnhccvr7AamBPMvumvE+wpj0fGlyR3DSds7XiB4CMpCa8sSzBilHFaVSWW4CjVb5b0BXcSqUF+FqfZa8fCX0OFYOzuuPG1yQ0VH4/aLUurH8EFAY7klFZHGogChx6SMr+BE5xLeme/7P6Bfx+Zh9bDoDaAAAAAElFTkSuQmCC" alt="play-icon"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAyElEQVRIS+2W4REBMRSE96sAHegAFSiBDrRAB3SgBDpQwpVABzpwKlhzM+EPl7txuJuR/E1md/bLS95DLS1a8lUy/hn57qK23Ze0kHQCshgS28Nwdg+cY2crE9s+SJoFkQlwLBO0nUvqScqBQVPjwmgURFbA9pVgIHO57wHRUHUSF3inQXADrCOJnYzL6CTUT2Rsp+JKz+lRF7bTB1LaJzr9gbzTFq9A0ccbJS4ElpKyGoPAWNJc0q7xIPCtIazyjpPxpwj8H+obgcOmH0UOq+wAAAAASUVORK5CYII=" alt="pause-icon"> </button> <div class="slider__content"> <img class="img slider__img" src="//repo.bfw.wiki/bfwrepo/image/5d653bd0990d0.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" alt="cover"> <img class="img slider__img" src="//repo.bfw.wiki/bfwrepo/image/5d653bd0990d0.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" alt="cover"> <img class="img slider__img" src="//repo.bfw.wiki/bfwrepo/image/5d653bd0990d0.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" alt="cover"> <img class="img slider__img" src="//repo.bfw.wiki/bfwrepo/image/5d653bd0990d0.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" alt="cover"> <img class="img slider__img" src="//repo.bfw.wiki/bfwrepo/image/5d653bd0990d0.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90g" alt="cover"> <img class="img slider__img" src="//repo.bfw.wiki/bfwrepo/image/5d653bd0990d0.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" alt="cover"> <img class="img slider__img" src="//repo.bfw.wiki/bfwrepo/image/5d653bd0990d0.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" alt="cover"> </div> </div> <div class="player__controls"> <button class="player__button back"> <img class="img" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAABDElEQVRIS+2VPxLBQBSHfy/RaRxBbwYFvatIraIxImsl/pQ0armCIziCGb0DOIAGa3aYESYSM3azimy98779frvvLcHQIkNc5ODMks+j/p+oR67bKNjCKZZOvW53cVJ1stQ79j13D6BCRCvPn3SSwJwP6tYFIwAbFszCpL3fgMWjQMiCaftTsTEbchJCQgHQlgWT1q/gA4AygFiwtLTPtBaE+hOkGfxqGfXTBI631AzmvF+2LraMP2FpMDYGlpr3tiHZLrV4bQ3GUVDmjysKj7dXY2xmgATM3QmBKhHWnj910kemtQSuoYKR2W8CtlM4X9lgPj9m9kmoAr3XSf0kcrCqBPKoVSWZWsdY1De+ZJsfVr5RfAAAAABJRU5ErkJggg==" alt="back-icon"> </button> <p class="player__context slider__context"> <strong class="slider__name"></strong> <span class="player__title slider__title"></span> </p> <button class="player__button next"> <img class="img" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAABIklEQVRIS+2VMU7DMBSG/4e79AAcgB0JOAFHgCO0MxNjaWMcu4660Ik5XIUdhoLE3iOUga32QxEggpQmWCmukOLZ/j9/f6wXwo4W7YiLDhyt+a7q/1n1fH7Zf1v1b9aO8tTaxzqLxm+sk6sBgDMvkCqVLerCjJzcMvMFgBdp7GFL8OQe4NMihJhVMs3STYE6Gd8BKC4KaWyt1C+Mv8EfcCxcj4dV9iXwUhp7sDXjclCVfRRwlX008GcDKy/ciVKzZWzwqxfuODb4yQsefD20KMZMlF7rqSo/uL8G/7CMAq6y3ADexgApRiade8GqeWSOc2YMifCcaHvUaoCE/K6y0Wh/3dvTgMulmT1EA4dcsnFWh4SF7O3AIW212ttV3aq+kMPvudyyH69/UI0AAAAASUVORK5CYII=" alt="next-icon"> </button> <div class="progres"> <div class="progres__filled"></div> </div> </div> </div> <ul class="player__playlist list"> <li class="player__song"> <img class="player__img img" src="//repo.bfw.wiki/bfwrepo/image/5d653bd0990d0.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" alt="cover"> <p class="player__context"> <b class="player__song-name">no time</b> <span class="flex"> <span class="player__title">lastlings</span> &l.........完整代码请登录后点击上方下载按钮下载查看
网友评论0