微信小程序开发之麦克风动画 帧动画 放大 淡出


Posted in Javascript onApril 18, 2017

想做个录音机,第一步就卡在麦克风动画这里了.

先上gif.再吐槽.

微信小程序开发之麦克风动画 帧动画 放大 淡出

① 上面gif中声波的动画是个半成品.没有循环播放.在微信小程序的开发文档上找了很久,也没找到循环模式的参数设置.用setInterval()并不执行动画.我在微信小程序文档 动画最下面找到这么一行字.这个锅是不是可以甩出去了?

ps:如果有同学能实现动画循环,一定告诉我.

微信小程序开发之麦克风动画 帧动画 放大 淡出

② 麦克风里面是个帧动画.没有前端的基础,只能用非主流的办法凑合了.

用wx:if{{}}判断js中定义的值是不是等于图片对应的数字来控制图片的显示和隐藏.css中应该有更好的方法.我css基础不牢,就不说了.

上代码:

1.index.wxml

<!--index.wxml--> 
<view class="voice-style" bindtap="startSpeak"> 
<image class="bg-style" src="../../images/voice_icon_speaking_bg_normal.png" ></image> 
<image class="bg-style" animation="{{spreakingAnimation}}" src="../../images/voice_video_loading_0.png"></image> 
<image class="bg-style" animation="{{spreakingAnimation_1}}" src="../../images/voice_video_loading_0.png"></image> 
<image class="bg-style" animation="{{spreakingAnimation_2}}" src="../../images/voice_video_loading_0.png"></image> 
<image class="sound-style" src="../../images/voice_icon_speech_sound_1.png" ></image> 
<image wx:if="{{j==2}}" class="sound-style" src="../../images/voice_icon_speech_sound_2.png" ></image> 
<image wx:if="{{j==3}}" class="sound-style" src="../../images/voice_icon_speech_sound_3.png" ></image> 
<image wx:if="{{j==4}}" class="sound-style" src="../../images/voice_icon_speech_sound_4.png" ></image> 
<image wx:if="{{j==5}}"class="sound-style" src="../../images/voice_icon_speech_sound_5.png" ></image> 
</view>

2.index.js

//index.js 
//获取应用实例 
var app = getApp() 
Page({ 
 data: { 
  spreakingAnimation: {},//放大动画 
  j: 1,//帧动画初始图片 
  isSpeaking: false,//是否在录音状态 
 }, 
 onLoad: function () { 
 }, 
 //点击开始说话 
 startSpeak: function () { 
  var _this = this; 
  if (!this.data.isSpeaking) { 
   speaking.call(this); 
   this.setData({ 
    isSpeaking: true 
   }) 
  } else { 
   //去除帧动画循环 
   clearInterval(this.timer) 
   this.setData({ 
    isSpeaking: false, 
    j: 1 
   }) 
  } 
 }, 
}) 

function speaking() { 
 //话筒帧动画 
 var i = 1; 
 this.timer = setInterval(function () { 
  i++; 
  i = i % 5; 
  _this.setData({ 
   j: i 
  }) 
  return 
 }, 200); 
 //波纹放大,淡出动画 
 var _this = this; 
 var animation = wx.createAnimation({ 
  duration: 1000 
 }) 
 animation.opacity(0).scale(3, 3).step();//修改透明度,放大 
 this.setData({ 
  spreakingAnimation: animation.export() 
 }) 
 setTimeout(function(){ 
  //波纹放大,淡出动画 
 var animation = wx.createAnimation({ 
  duration: 1000 
 }) 
 animation.opacity(0).scale(3, 3).step();//修改透明度,放大 
 _this.setData({ 
  spreakingAnimation_1: animation.export() 
 }) 
 },250) 
  setTimeout(function(){ 
  //波纹放大,淡出动画 
 var animation = wx.createAnimation({ 
  duration: 1000 
 }) 
 animation.opacity(0).scale(3, 3).step();//修改透明度,放大 
 _this.setData({ 
  spreakingAnimation_2: animation.export() 
 }) 
 },500) 
}

3.index.wxss

/**index.wxss**/ 
.voice-style { 
 margin-top: 400px; 
 display: flex; 
 position: relative; 
 flex-direction: column; 
 align-items: center; 
} 
.bg-style { 
 position: absolute; 
 width: 100px; 
 height: 100px; 
} 
.sound-style{ 
 position: absolute; 
 width: 37.6px; 
 height: 60px; 
 margin-top: 20px; 
}

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持三水点靠木!

Javascript 相关文章推荐
javascript对象的property和prototype是这样一种关系
Mar 24 Javascript
jQuery操作input值的各种方法总结
Nov 21 Javascript
javascript引用赋值(地址传值)用法实例
Jan 13 Javascript
js判断文本框剩余可输入字数的方法
Feb 04 Javascript
jQuery Ajax调用WCF服务详细教程
Mar 31 Javascript
微信小程序 轮播图swiper详解及实例(源码下载)
Jan 11 Javascript
Node.js的特点详解
Feb 03 Javascript
关于vue.js v-bind 的一些理解和思考
Jun 06 Javascript
vue编译打包本地查看index文件的方法
Feb 23 Javascript
JS简单生成由字母数字组合随机字符串示例
May 25 Javascript
vue.config.js常用配置详解
Nov 14 Javascript
微信小程序动态设置图片大小的方法
Nov 21 Javascript
JavaScript错误处理和堆栈追踪详解
Apr 18 #Javascript
微信小程序开发之从相册获取图片 使用相机拍照 本地图片上传
Apr 18 #Javascript
微信小程序实战之自定义抽屉菜单(7)
Apr 18 #Javascript
微信小程序--onShareAppMessage分享参数用处(页面分享)
Apr 18 #Javascript
微信小程序实战之自定义toast(6)
Apr 18 #Javascript
Jquery-data的三种用法
Apr 18 #jQuery
微信小程序实战之登录页面制作(5)
Mar 30 #Javascript
You might like
php数组查找函数in_array()、array_search()、array_key_exists()使用实例
2014/04/29 PHP
Yii视图CGridView列表用法实例分析
2016/07/12 PHP
JS中==与===操作符的比较
2009/03/21 Javascript
让IE8支持DOM 2(不用框架!)
2009/12/31 Javascript
JavaScript移除数组元素减少长度的方法
2013/09/05 Javascript
JavaScript中逗号运算符介绍及使用示例
2015/03/13 Javascript
jquery验证邮箱格式是否正确实例讲解
2015/11/16 Javascript
JS &amp; JQuery 动态添加 select option
2016/06/08 Javascript
再谈javascript注入 黑客必备!
2016/09/14 Javascript
js实现砖头在页面拖拉效果
2020/11/20 Javascript
jQuery实现优雅的弹窗效果(6)
2017/02/08 Javascript
原生js实现放大镜
2017/02/20 Javascript
socket.io学习教程之深入学习篇(三)
2017/04/29 Javascript
js实现关闭网页出现是否离开提示
2017/12/07 Javascript
react native基于FlatList下拉刷新上拉加载实现代码示例
2018/09/30 Javascript
python中os模块详解
2016/10/14 Python
深入理解python中的select模块
2017/04/23 Python
python+opencv实现的简单人脸识别代码示例
2017/11/14 Python
Python中的defaultdict与__missing__()使用介绍
2018/02/03 Python
对Python 语音识别框架详解
2018/12/24 Python
python3实现表白神器
2019/04/09 Python
python设计tcp数据包协议类的例子
2019/07/23 Python
用python3读取python2的pickle数据方式
2019/12/25 Python
Python内置数据类型list各方法的性能测试过程解析
2020/01/07 Python
python调用API接口实现登陆短信验证
2020/05/10 Python
在vscode中启动conda虚拟环境的思路详解
2020/12/25 Python
wordpress添加Html5的表单验证required方法小结
2020/08/18 HTML / CSS
英国优质鞋类专家:Robinson’s Shoes
2017/12/08 全球购物
Merrell美国官网:美国登山运动鞋品牌
2018/02/07 全球购物
意大利珠宝店:Luxury Zone
2019/01/05 全球购物
什么是.net的Remoting技术
2016/07/08 面试题
开学典礼决心书
2014/03/11 职场文书
幼儿园教师获奖感言
2014/03/11 职场文书
房产委托公证书
2014/04/08 职场文书
岗位职责说明书模板
2014/07/30 职场文书
Python办公自动化PPT批量转换操作
2021/09/15 Python