您现在的位置是:html5+cpg电子赏金女王夺宝ss3制作音乐列表播放器源码pc蛋蛋28官网入口 >>正文
html5+cpg电子赏金女王夺宝ss3制作音乐列表播放器源码pc蛋蛋28官网入口
一串骊珠网93388人已围观
简介mp3音乐播放器列表ui工具特效,支持上一首或下一首音乐背景切换效果。hpg电子赏金女王夺宝tml5+css3制作音乐列表播放器,---在线演示// Designed by: Mauricio Bu...
mp3音乐播放器列表ui工具特效,支持上一首或下一首音乐背景切换效果。
hpg电子赏金女王夺宝pc蛋蛋28官网入口strong>tml5+css3制作音乐列表播放器,---在线演示
// Designed by: Mauricio Bucardo// Original image: https://dribbble.com/shots/6957353-Music-Player-Widget"use strict";// add elemntsconst bgBody = ["#e5e7e9", "#ff4545", "#f8ded3", "#ffc382", "#f5eda6", "#ffcbdc", "#dcf3f3"];const body = document.body;const player = document.querySelector(".player");const playerHeader = player.querySelector(".player__header");const playerControls = player.querySelector(".player__controls");const playerPlayList = player.querySelectorAll(".player__song");const playerSongs = player.querySelectorAll(".audio");const playButton = player.querySelector(".play");const nextButton = player.querySelector(".next");const backButton = player.querySelector(".back");const playlistButton = player.querySelector(".playlist");const slider = player.querySelector(".slider");const sliderContext = player.querySelector(".slider__context");const sliderName = sliderContext.querySelector(".slider__name");const sliderTitle = sliderContext.querySelector(".slider__title");const sliderContent = slider.querySelector(".slider__content");const sliderContentLength = playerPlayList.length - 1;const sliderWidth = 100;let left = 0;let count = 0;let song = playerSongs[count];let isPlay = false;const pauseIcon = playButton.querySelector("img[alt = 'pause-icon']");const playIcon = playButton.querySelector("img[alt = 'play-icon']");const progres = player.querySelector(".progres");const progresFilled = progres.querySelector(".progres__filled");let isMove = false;// creat functionsfunction openPlayer() { playerHeader.classList.add("open-header"); playerControls.classList.add("move"); slider.classList.add("open-slider"); }function closePlayer() { playerHeader.classList.remove("open-header"); playerControls.classList.remove("move"); slider.classList.remove("open-slider"); }function next() { if (count == sliderContentLength) { count = count; return } left += sliderWidth; left = Math.min(left, (sliderContentLength) * sliderWidth); sliderContent.style.transform = `translate3d(-${left}%, 0, 0)`; count++; changeSliderContext(); changeBgBody(); selectSong();}function back() { if (count == 0) { count = count return } left -= sliderWidth; left = Math.max(0, left); sliderContent.style.transform = `translate3d(-${left}%, 0, 0)`; count--;}function changeSliderContext() { sliderContext.style.animationName = "opacity"; sliderName.textContent = playerPlayList[count].querySelector(".player__title").textContent; sliderTitle.textContent = playerPlayList[count].querySelector(".player__song-name").textContent; if (sliderName.textContent.length > 16) { const textWrap = document.createElement("span"); textWrap.className = "text-wrap"; textWrap.innerHTML = sliderName.textContent + " " + sliderName.textContent; sliderName.innerHTML = ""; sliderName.append(textWrap); } if (sliderTitle.textContent.length >= 18) { const textWrap = document.createElement("span"); textWrap.className = "text-wrap"; textWrap.innerHTML = sliderTitle.textContent + " " + sliderTitle.textContent; sliderTitle.innerHTML = ""; sliderTitle.append(textWrap); }}function changeBgBody() { body.style.backgroundColor = bgBody[count];}function selectSong() { song = playerSongs[count]; for (const item of playerSongs) { if (item != song) { item.pause(); item.currentTime = 0; } } if (isPlay) song.play(); }function playSong() { if (song.paused) { song.play(); playIcon.style.display = "none"; pauseIcon.style.display = "block"; }else{ song.pause(); isPlay = false; playIcon.style.display = ""; pauseIcon.style.display = ""; } }function progresUpdate() { const progresFilledWidth = (this.currentTime / this.duration) * 100 + "%"; progresFilled.style.width = progresFilledWidth; if (this.duration == this.currentTime) { next(); } if (count == sliderContentLength && song.currentTime == song.duration) { playIcon.style.display = "block"; pauseIcon.style.display = ""; isPlay = false; }}function scurb(e) { // If we use e.offsetX, we have trouble setting the song time, when the mousemove is running const currentTime = ( (e.clientX - progres.getBoundingClientRect().left) / progres.offsetWidth ) * song.duration; song.currentTime = currentTime;}function durationSongs() { let min = parseInt(this.duration / 60); if (min < 10) min = "0" + min; let sec = parseInt(this.duration % 60); if (sec < 10) sec = "0" + sec; const playerSongTime = `${min}:${sec}`; this.closest(".player__song").querySelector(".player__song-time").append(playerSongTime);}changeSliderContext();// add eventssliderContext.addEventListener("click", openPlayer);sliderContext.addEventListener("animationend", () => sliderContext.style.animationName ='');playlistButton.addEventListener("click", closePlayer);nextButton.addEventListener("click", next);backButton.addEventListener("click", () => { back(); changeSliderContext(); changeBgBody(); selectSong();});playButton.addEventListener("click", () => { isPlay = true; playSong();});playerSongs.forEach(song => { song.addEventListener("loadeddata" , durationSongs); song.addEventListener("timeupdate" , progresUpdate); });progres.addEventListener("mousedown", (e) => { scurb(e); isMove = true; song.muted = true;});document.addEventListener("mousemove", (e) => isMove && scurb(e));document.addEventListener("mouseup", () => { isMove = false song.muted = false;});document.ondragstart = () => { return false};
Tags:
相关文章
javascript位运算符与赋值运算符
html5+cpg电子赏金女王夺宝ss3制作音乐列表播放器源码pc蛋蛋28官网入口一、位运算符PS:在一般的应用中,我们基本上用不到位运算符。虽然,它比较基于底层,性能和速度会非常好,而就是因为比较底层,使用的难度也很大。位运算符有七种,分别是:位非NOT(~)、位与AND(&am...
阅读更多
阿里云虚拟主机:网站木马查杀与数据自动备份
html5+cpg电子赏金女王夺宝ss3制作音乐列表播放器源码pc蛋蛋28官网入口购买过阿里云虚拟主机都知道,虚拟主机服务器后台支持木马查杀、日志分析、网站数据自动备份、7.0,7.1等功能。如果数据库支持5.5以上就更好了。阿里云虚拟主机的网站木马查杀功能,十分适合对网站安全不了...
阅读更多
wordpress禁用古腾堡区块内容编辑器方法
html5+cpg电子赏金女王夺宝ss3制作音乐列表播放器源码pc蛋蛋28官网入口wordpress现在的最新版本内容或页面编辑器默认为Gutenberg(古腾堡),是一个写作体验现代化的编辑器,如下图所示,左边支持区块,样板、媒体设置显示,右边支持视图、编辑器、工具、偏好设置等。...
阅读更多