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 this关键字使用分析
Oct 21 Javascript
javascript cookie操作类的实现代码小结附使用方法
Jun 02 Javascript
Jquery截取中文字符串的实现代码
Dec 22 Javascript
jquery 插件开发 extjs中的extend用法小结
Jan 04 Javascript
jQuery判断checkbox选中状态
May 12 Javascript
老生常谈JQuery data方法的使用
Sep 09 Javascript
Vue.js 递归组件实现树形菜单(实例分享)
Dec 21 Javascript
图文详解Javascript中的上下文和作用域
Feb 15 Javascript
基于JavaScript实现数码时钟效果
Mar 30 Javascript
Vue中正确使用jQuery的方法
Oct 30 jQuery
jQuery实现图片简单轮播功能示例
Aug 13 jQuery
js canvas实现5张图片合成一张图片
Jul 15 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 Smarty 字符比较代码
2011/02/27 PHP
PHP使用递归方式列出当前目录下所有文件的方法
2015/06/02 PHP
Linux系统中为php添加pcntl扩展
2016/08/28 PHP
jQuery用unbind方法去掉hover事件及其他方法介绍
2013/03/18 Javascript
jQuery删除节点的三个方法即remove()detach()和empty()
2013/12/27 Javascript
JavaScript中的立即执行函数表达式介绍
2015/03/15 Javascript
javascript中递归函数用法注意点
2015/07/30 Javascript
简单总结JavaScript中的String字符串类型
2016/05/26 Javascript
最佳的JavaScript错误处理实践
2016/07/16 Javascript
通过Ajax使用FormData对象无刷新上传文件方法
2016/12/08 Javascript
jQuery基于Ajax方式提交表单功能示例
2017/02/10 Javascript
浅谈在fetch方法中添加header后遇到的预检请求问题
2017/08/31 Javascript
vue-cli中的webpack配置详解
2017/09/25 Javascript
angularJs 表格添加删除修改查询方法
2018/02/27 Javascript
JavaScript获取用户所在城市及地理位置
2018/04/21 Javascript
解决layer弹层遮罩挡住窗体的问题
2018/08/17 Javascript
微信小程序日历/日期选择插件使用方法详解
2018/12/28 Javascript
[01:25]DOTA2自定义游戏灵园鬼域等你踏足
2015/10/30 DOTA
[44:33]EG vs Liquid 2018国际邀请赛小组赛BO2 第二场 8.18
2018/08/19 DOTA
零基础写python爬虫之爬虫编写全记录
2014/11/06 Python
Python实现单词拼写检查
2015/04/25 Python
Python实现的十进制小数与二进制小数相互转换功能
2017/10/12 Python
Python用csv写入文件_消除空余行的方法
2018/07/06 Python
基于随机梯度下降的矩阵分解推荐算法(python)
2018/08/31 Python
NLTK 3.2.4 环境搭建教程
2018/09/19 Python
python批量获取html内body内容的实例
2019/01/02 Python
Python3 sys.argv[ ]用法详解
2019/10/24 Python
python 实现视频 图像帧提取
2019/12/10 Python
python标准库os库的函数介绍
2020/02/12 Python
jupyter note 实现将数据保存为word
2020/04/14 Python
Python urllib.request对象案例解析
2020/05/11 Python
PyCharm2020.1.1与Python3.7.7的安装教程图文详解
2020/08/07 Python
python3 re返回形式总结
2020/11/20 Python
六年级情感作文之500字
2019/10/23 职场文书
利用Matlab绘制各类特殊图形的实例代码
2021/07/16 Python
JavaScript 反射学习技巧
2021/10/16 Javascript