js微信应用场景之微信音乐相册案例分享


Posted in Javascript onAugust 11, 2017

这个demo只是一个js微信音乐相册案例大概思路,具体还需要根据情况来进行

<!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-->
    <div 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> -->
    </div>
    <!--CONTAINER-->
    <div class='swiper-container'>
      <div class='swiper-wrapper'>
        <div class='swiper-slide page1'>
          <img src="img/swiper/page1-text1.png" alt="">
          <img src="img/swiper/page1-text2.png" alt="">
          <img src="img/swiper/page1-text3.png" alt="">
          <img src="img/swiper/page1-text4.png" alt="">
        </div>
        <div class='swiper-slide page2'>
          <img src="img/swiper/page2-text1.png" alt="">
          <img src="img/swiper/page2-text2.png" alt="">
          <img src="img/swiper/page2-text3.png" alt="">
          <img src="img/swiper/page2-text4.png" alt="">
        </div>
      </div>
    </div>
    <!--ARROW-->
    <div class='arrow'></div>

    
  </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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
javascript 打开页面window.location和window.open的区别
Mar 17 Javascript
移动节点的jquery代码
Jan 13 Javascript
js实现日历可获得指定日期周数及星期几示例分享(js获取星期几)
Mar 14 Javascript
BootStrap文件上传样式超好看【持续更新】
May 10 Javascript
layui前段框架日期控件使用方法详解
May 19 Javascript
bootstrap插件treeview实现全选父节点下所有子节点和反选功能
Jul 21 Javascript
vue使用rem实现 移动端屏幕适配
Sep 26 Javascript
解决Vue中引入swiper,在数据渲染的时候,发生不滑动的问题
Sep 27 Javascript
vue基础之v-bind属性、class和style用法分析
Mar 11 Javascript
Vue.js递归组件实现组织架构树和选人功能
Jul 04 Javascript
Openlayers显示地理位置坐标的方法
Sep 28 Javascript
JS如何实现在弹出窗口中加载页面
Dec 03 Javascript
Angular模板表单校验方法详解
Aug 11 #Javascript
AngularJs导出数据到Excel的示例代码
Aug 11 #Javascript
Vue 表单控件绑定的实现示例
Aug 11 #Javascript
Angular4实现动态添加删除表单输入框功能
Aug 11 #Javascript
node中使用es5/6以及支持性与性能对比
Aug 11 #Javascript
ionic2屏幕适配实现适配手机、平板等设备的示例代码
Aug 11 #Javascript
JSON对象转化为字符串详解
Aug 11 #Javascript
You might like
php判断字符以及字符串的包含方法属性
2008/08/30 PHP
PHP array操作10个小技巧分享
2011/06/23 PHP
PHP模拟QQ登录的方法
2015/07/29 PHP
PHP正则匹配日期和时间(时间戳转换)的实例代码
2016/12/14 PHP
Laravel 实现Controller向blade前台模板赋值的四种方式小结
2019/10/22 PHP
extjs grid取到数据而不显示的解决
2008/12/29 Javascript
css结合js制作下拉菜单示例代码
2014/02/27 Javascript
jquery实现模拟百分比进度条渐变效果代码
2015/10/29 Javascript
JQ选择器_选择同类元素的第N个子元素的实现方法
2016/09/08 Javascript
深入理解js中的加载事件
2017/02/08 Javascript
js仿网易表单及时验证功能
2017/03/07 Javascript
基于Vue过渡状态实例讲解
2017/09/14 Javascript
jQuery扩展方法实现Form表单与Json互相转换的实例代码
2018/09/05 jQuery
开发一个Parcel-vue脚手架工具(详细步骤)
2018/09/22 Javascript
小程序:授权、登录、session_key、unionId的详解
2019/05/15 Javascript
微信小程序跨页面传递data数据方法解析
2019/12/13 Javascript
[57:22]2018DOTA2亚洲邀请赛 4.7总决赛 LGD vs Mineski 第五场
2018/04/10 DOTA
Python写的英文字符大小写转换代码示例
2015/03/06 Python
python中装饰器级连的使用方法示例
2017/09/29 Python
python编写简单端口扫描器
2019/09/04 Python
Python手绘可视化工具cutecharts使用实例
2019/12/05 Python
python socket通信编程实现文件上传代码实例
2019/12/14 Python
Python线程threading模块用法详解
2020/02/26 Python
在django项目中导出数据到excel文件并实现下载的功能
2020/03/13 Python
在Django中自定义filter并在template中的使用详解
2020/05/19 Python
Python利用matplotlib绘制散点图的新手教程
2020/11/05 Python
Interflora澳大利亚:同日鲜花速递
2019/06/25 全球购物
请解释在new与override的区别
2012/10/29 面试题
装潢设计实习自我鉴定
2013/09/19 职场文书
九年级政治教学反思
2014/02/06 职场文书
《秋姑娘的信》教学反思
2014/02/28 职场文书
副乡长民主生活会个人对照检查材料思想汇报
2014/10/01 职场文书
食品质检员岗位职责
2015/04/08 职场文书
沂蒙六姐妹观后感
2015/06/08 职场文书
立秋之描写立秋的作文(五年级)
2019/08/08 职场文书
MySQL中rank() over、dense_rank() over、row_number() over用法介绍
2022/03/23 MySQL