Share an example of using JavaScript to create a WeChat music album
This article mainly shares the WeChat music album case of js WeChat application scenario. It has certain reference value. Interested friends can refer to it.
This demo is just a js WeChat music album The general idea of the case, the specifics need to be carried out according to the situation
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="reset.css" rel="external nofollow" > <link rel="stylesheet" href="swiper.min.css" rel="external nofollow" > <link rel="stylesheet" type="text/css" href="animate.css" rel="external nofollow" > <style> html,body{ width:100%; height:100%; overflow:hidden; } html{ font-size:100px;/*设计稿640*960*/ } .main,.swiper-container,.swiper-slide{ width:100%; height:100%; overflow:hidden; } .page1{ position:relative; background:url("../img/swiper/bg1.jpg") no-repeat; background-size:cover; } .page1 img{ position:absolute; opacity:0; } .page1 img:nth-child(1){ left:2rem; top:.28rem; width:.96rem; height:2.32rem; } .page1 img:nth-child(2){ right:0; top:.28rem; width:3.7rem; height:6rem; } .page1 img:nth-child(3){ left:.5rem; bottom:.8rem; width:5.5rem; height:5.12rem; } .page1 img:nth-child(4){ left:-1.6rem; bottom:0; width:7.86rem; height:5.88rem; } /*实现切换完成后页面中的元素在开始运动的思想:开始的时候当前的这个区域没有对应的ID,当切换到这个区域的时候,我们为其增加ID,在css中我们把所有的动画效果都放在指定的ID下,这样的话只需要让区域有ID,里面的子元素就有动画了*/ #page1 img:nth-child(1){ /*注意移动端的样式写两套 并且不加webkit的在后*/ -webkit-animation:bounceInLeft 1s linear 0s 1 both; animation:bounceInLeft 1s linear 0s 1 both; } #page1 img:nth-child(2){ /*注意移动端的样式写两套 并且不加webkit的在后*/ -webkit-animation:bounceInRight 1s linear .3s 1 both; animation:bounceInRight 1s linear .3s 1 both; } #page1 img:nth-child(3){ /*注意移动端的样式写两套 并且不加webkit的在后*/ -webkit-animation:bounceInUp 1s linear .6s 1 both; animation:bounceInUp 1s linear .6s 1 both; } #page1 img:nth-child(4){ /*注意移动端的样式写两套 并且不加webkit的在后*/ -webkit-animation:bounceInUp 1s linear .9s 1 both; animation:bounceInUp 1s linear .9s 1 both; } .page2{ position:relative; background:url("../img/swiper/bg2.jpg") no-repeat; background-size:cover; } .page2 img{ position:absolute; top:2.5rem; opacity:0; } .page2 img:nth-child(1){ top:0; left:0; width:3.4rem; height:1.74rem; } .page2 img:nth-child(2){ left:1.48rem; } .page2 img:nth-child(3){ left:3.2rem; } .page2 img:nth-child(4){ left:4.7rem; } #page2 img:nth-child(1){ -webkit-animation:bounceInLeft 1s linear 0s 1 both; animation:bounceInLeft 1s linear 0s 1 both; } #page2 img:nth-child(2){ -webkit-animation:zoomIn 1s linear .3s 1 both; animation:zoomIn 1s linear .3s 1 both; } #page2 img:nth-child(3){ -webkit-animation:zoomIn 1s linear .6s 1 both; animation:zoomIn 1s linear .6s 1 both; } #page2 img:nth-child(4){ -webkit-animation:zoomIn 1s linear .9s 1 both; animation:zoomIn 1s linear .9s 1 both; } .arrow{ position:absolute; left:50%; bottom:.2rem; z-index:10; margin-left:-.24rem; width:.48rem; height:.36rem; background:url("../img/swiper/web-swipe-tip.png") no-repeat; background-size:100% 100%; -webkit-animation:bounce 1s linear 0s infinite both; animation:bounce 1s linear 0s infinite both; } .music{ display:none; position:absolute; top:.2rem; right:.2rem; z-index:10; width:.6rem; height:.6rem; background:url("../audio/music.svg") no-repeat; background-size:100% 100%; } .music.move{ -webkit-animation :musicMove 1s linear 0s infinite both; animation :musicMove 1s linear 0s infinite both; } .music audio{ display:none; } @-webkit-keyframes musicMove{ 0%{ -webkit-transform:rotate(0deg); transform:rotate(0deg); } 100%{ -webkit-transform:rotate(360deg); transform:rotate(360deg); } } @keyframes musicMove{ 0%{ -webkit-transform:rotate(0deg); transform:rotate(0deg); } 100%{ -webkit-transform:rotate(360deg); transform:rotate(360deg); } } </style> </head> <body> <section class='main'> <!--MUSIC--> <p class='music' id='musicMenu'> <audio src="beyond.mp3" preload = 'none' loop autoplay></audio id='musicAudio'> <!-- <audio> <source src='beyond.mp3' type='audio/mpeg'/> <source src='beyond.wav' type='audio/wav'/> <source src='beyond.ogg' type='audio/ogg'/> </audio> --> </p> <!--CONTAINER--> <p class='swiper-container'> <p class='swiper-wrapper'> <p class='swiper-slide page1'> <img src="/static/imghwm/default1.png" data-src="img/swiper/page1-text1.png" class="lazy" alt=""> <img src="/static/imghwm/default1.png" data-src="img/swiper/page1-text2.png" class="lazy" alt=""> <img src="/static/imghwm/default1.png" data-src="img/swiper/page1-text3.png" class="lazy" alt=""> <img src="/static/imghwm/default1.png" data-src="img/swiper/page1-text4.png" class="lazy" alt=""> </p> <p class='swiper-slide page2'> <img src="/static/imghwm/default1.png" data-src="img/swiper/page2-text1.png" class="lazy" alt=""> <img src="/static/imghwm/default1.png" data-src="img/swiper/page2-text2.png" class="lazy" alt=""> <img src="/static/imghwm/default1.png" data-src="img/swiper/page2-text3.png" class="lazy" alt=""> <img src="/static/imghwm/default1.png" data-src="img/swiper/page2-text4.png" class="lazy" alt=""> </p> </p> </p> <!--ARROW--> <p class='arrow'></p> </section> <script charset='utf-8' src='swiper.min.js'></script> <script> //rem ~function(){ var desW = 640, winW = document.documentElement.clientWidth, ratio = winW / desW, oMain = document.querySelector(".main"); if(winW>desW){ oMain.style.margin = "0 auto"; oMain.style.width = desW + 'px'; return; } document.documentElement.style.fontSize = ratio*100+"px"; }() new Swiper('.swiper-container',{ direction:"vertical", loop:true, /*当切换结束后,给当前展示的区域添加对应的ID,由此实现对应的动画效果*/ onSlideChangeEnd:function(swiper){ var slideAry = swiper.slides;//获取当前一共有多少个活动快(包含loop模式前后多加的两个) var curIn = swiper.activeIndex;//当前展示的这个区域的索引 var total = slideAry.length; //计算ID是PAGE? var targetId = 'page'; switch(curIn){ case 0: targetId += total - 2; break; case total - 1: targetId += 1; break; default: targetId += curIn } //给当前的活动块设置ID即可,还要把其余的移除 [].forEach.call(slideAry,function(item,index){ if(curIn === index){ item.id = targetId; return; } item.id = null; }) slideAry[curIn].id = targetId; //最后把animate.css里面的动画to里面添加opacity:1 } }) //MUSIC ~function(){ var musicMenu = document.getElementById('musicMenu'), musicAudio = document.getElementById('musicAudio'); musicMenu.addEventListener('click',function(){ if(musicAudio.paused){ musicAudio.play(); musicMenu.className = "music move"; return; } musicAudio.pause(); musicMenu.className = "music"; }) function controlMusic(){ musicAudio.volume = 0.1; musicAudio.play(); musicAudio.addEventListener('canplay',function(){ musicMenu.style.display = "block"; musicMenu.className = "music move"; }) } window.setTimeout(controlMusic,1000) }() </script> </body> </html>
The above is the detailed content of Share an example of using JavaScript to create a WeChat music album. For more information, please follow other related articles on the PHP Chinese website!

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version
