suibi
- html圆角属性代码讲解(html怎么设置圆角矩形教程)
- win32和win64的区别介绍(猜猜win7哪个系统版本最好用)
- 什么是js代码编程(js编程特点详细介绍)
- photoshop版本顺序近32年发展历程(ps各个版本及年份介绍)
- 学会node.js能做什么(nodejs开发前端的特点)
- linux改IP地址命令怎么改(一分钟修改服务器ip地址)
- linux修改ip地址的命令运行方法(一分钟完成linux更改ip)
- php数组函数的使用方法(常用的数组函数代码)
- ps人物抠图步骤教程(ps图片素材人物高清修图过程)
- js数组indexof方法找某个数(js判断数组中是否包含某个对象用法)
- php跨域问题的解决方案(一招彻底解决跨域问题)
- mysql密码忘了怎么找回(手把手教你找回mysql登录密码)
- html音乐播放器插件代码(Vue制作网页音乐播放器)
- python解释器是什么意思(详细讲解python语言解释器)
- ps的全称是什么(ps全称叫什么名字)
- python保留2位小数点怎么实现(保留2位小数实现方法)
- springmvc原理实现机制详解(mvc工作原理最简单的概述)
- html背景图片全屏特效代码(超简单的网页设计方法)
- css如何设置背景颜色透明度(实例分享css透明度属性代码)
- vue和react的区别以及优劣势(你知道大公司用react还是vue吗)
- vue的优势及特点有哪些(带你了解vue的强大之处)
- linux删除分区信息命令(删除逻辑分区的详细步骤Linux)
- css文字水平居中对齐代码设置(实例css让文字居中代码)
- 后缀xml是什么文件格式(详解xml格式文件)
- 电脑p图软件哪个好用(电脑用什么ps软件最好)
- win7桌面的文件在c盘哪个位置(桌面文件路径如何查看)
- 查看数据库字符集格式语句(一文读懂数据库的字符集)
- vue与react的区别有什么不同(Vue和React深度比较)
- Linux端口转发脚本怎么设置(端口转发最常见的使用场景)
- excel阅读模式找不到怎么办(表格没有找到阅读模式怎么设置)
- js转义字符用法案例解析(转义字符的定义)
- ps格式介绍(详解ps文件有多少种格式)
- 如何查看nodejs版本是多少(node版本的查看方法)
- 服务器的作用和用途(网络服务器的种类介绍)
- 怎样做网站(分享制作自己网站的流程步骤)
- linux删除目录的命令是什么(linux如何删除指定文件目录)
- html视频标签属性代码是什么(网页视频标签代码怎么写)
- dreamwearver是什么软件(推荐一款前端开发工具)
- python中return的用法及意义和实践详解
- chrome禁用js脚本原理(谷歌浏览器如何关闭js禁用)
html音乐播放器插件代码(Vue制作网页音乐播放器)
这是一款使用 Vue 制作的富有质感的方形 HTML5 音乐播放器,播放器左上角以浮起的方式显示封面,右侧是使用 svg 绘制的播放控制按钮,包含了收藏、上一首、下一首和播放,下面部分显示歌名、歌手名和播放进度条。这款播放器简洁精致,可用作独立的播放器使用。
制作过程
1、HTML
<div class="wrapper" id="app"> <div class="player"> <div class="player__top"> <div class="player-cover"> <transition-group :name="transitionName"> <div class="player-cover__item" v-if="$index === currentTrackIndex" :style="{ backgroundImage: `url(${track.cover})` }" v-for="(track, $index) in tracks" :key="$index" ></div> </transition-group> </div> <div class="player-controls"> <div class="player-controls__item -favorite" :class="{ active : currentTrack.favorited }" @click="favorite" > <svg class="icon"> <use xlink:href="#icon-heart-o"></use> </svg> </div> <a :href="currentTrack.url" target="_blank" class="player-controls__item"> <svg class="icon"> <use xlink:href="#icon-link"></use> </svg> </a> <div class="player-controls__item" @click="prevTrack"> <svg class="icon"> <use xlink:href="#icon-prev"></use> </svg> </div> <div class="player-controls__item" @click="nextTrack"> <svg class="icon"> <use xlink:href="#icon-next"></use> </svg> </div> <div class="player-controls__item -xl js-play" @click="play"> <svg class="icon"> <use xlink:href="#icon-pause" v-if="isTimerPlaying"></use> <use xlink:href="#icon-play" v-else></use> </svg> </div> </div> </div> <div class="progress" ref="progress"> <div class="progress__top"> <div class="album-info" v-if="currentTrack"> <div class="album-info__name">{{ currentTrack.artist }}</div> <div class="album-info__track">{{ currentTrack.name }}</div> </div> <div class="progress__duration">{{ duration }}</div> </div> <div class="progress__bar" @click="clickProgress"> <div class="progress__current" :style="{ width : barWidth }"></div> </div> <div class="progress__time">{{ currentTime }}</div> </div> <div v-cloak></div> </div></div>
2、CSS
.wrapper { width: 100%; display: flex; align-items: center; justify-content: center; min-height: 100vh; background-size: cover;}@media screen and (max-width: 700px), (max-height: 500px) { .wrapper { flex-wrap: wrap; flex-direction: column; }}.player { background: #eef3f7; width: 410px; min-height: 480px; box-shadow: 0px 15px 35px -5px rgba(50, 88, 130, 0.32); border-radius: 15px; padding: 30px;}@media screen and (max-width: 576px), (max-height: 500px) { .player { width: 95%; padding: 20px; margin-top: 75px; min-height: initial; padding-bottom: 30px; max-width: 400px; }}.player__top { display: flex; align-items: flex-start; position: relative; z-index: 4;}@media screen and (max-width: 576px), (max-height: 500px) { .player__top { flex-wrap: wrap; }}.player-cover { width: 300px; height: 300px; margin-left: -70px; flex-shrink: 0; position: relative; z-index: 2; border-radius: 15px; z-index: 1;}...
3、Javascript
new Vue({ el: '#app', data() { return { audio: null, circleLeft: null, barWidth: null, duration: null, currentTime: null, isTimerPlaying: false, tracks: [ { name: 'Dawn', artist: 'Skylike', cover: 'img/1.jpg', source: 'https://cdn.dowebok.com/mp3/2.mp3', url: 'https://www.dowebok.com/8636.html', favorited: false }, ... ], currentTrack: null, currentTrackIndex: 0, transitionName: null } }, created() { let vm = this this.currentTrack = this.tracks[0] this.audio = new Audio() this.audio.src = this.currentTrack.source this.audio.ontimeupdate = function () { vm.generateTime() } this.audio.onloadedmetadata = function () { vm.generateTime() } this.audio.onended = function () { vm.nextTrack() this.isTimerPlaying = true } for (let index = 0; index < this.tracks.length; index++) { const element = this.tracks[index] let link = document.createElement('link') link.rel = 'prefetch' link.href = element.cover link.as = 'image' document.head.appendChild(link) } }, methods: { play() { if (this.audio.paused) { this.audio.play() this.isTimerPlaying = true } else { this.audio.pause() this.isTimerPlaying = false } }, prevTrack() { this.transitionName = 'scale-in' this.isShowCover = false if (this.currentTrackIndex > 0) { this.currentTrackIndex-- } else { this.currentTrackIndex = this.tracks.length - 1 } this.currentTrack = this.tracks[this.currentTrackIndex] this.resetPlayer() }, nextTrack() { this.transitionName = 'scale-out' this.isShowCover = false if (this.currentTrackIndex < this.tracks.length - 1) { this.currentTrackIndex++ } else { this.currentTrackIndex = 0 } this.currentTrack = this.tracks[this.currentTrackIndex] this.resetPlayer() }, ... }})
到这里就制作完了,由于代码过长,上面所展示的并不是全部的,如需下载代码,请前往:
https://www.dowebok.com/8636.html
写笔记