微信小程序 Toast自定义实例详解


Posted in Javascript onJanuary 20, 2017

微信小程序 Toast自定义实例详解

实现类似于Android的Toast提示 

index.js:

var timer; 
var inputinfo = ""; 
var app = getApp() 
Page({ 
 data: { 
  animationData:"", 
  showModalStatus:false 
 }, 
  
 onLoad: function () { 
   
 }, 
 showModal: function () { 
  // 显示遮罩层 
  var animation = wx.createAnimation({ 
   duration: 200, 
   timingFunction: "linear", 
   delay: 0 
  }) 
  this.animation = animation 
  animation.translateY(200).step() 
  this.setData({ 
   animationData: animation.export(), 
   showModalStatus: true 
  }) 
  setTimeout(function () { 
   animation.translateY(0).step() 
   this.setData({ 
    animationData: animation.export() 
   }) 
  }.bind(this), 200) 
  console.log("准备执行"); 
   timer = setTimeout(function () { 
    if(this.data.showModalStatus){ 
     this.hideModal(); 
     console.log("是否执行"); 
   } 
  }.bind(this), 3000) 
 }, 
 clickbtn:function(){ 
  if(this.data.showModalStatus){ 
   this.hideModal(); 
  }else{ 
   this.showModal(); 
  } 
 }, 
 hideModal: function () { 
  if(timer != null){ 
   clearTimeout(timer); 
   timer = null; 
  } 
  // 隐藏遮罩层 
  var animation = wx.createAnimation({ 
   duration: 200, 
   timingFunction: "linear", 
   delay: 0 
  }) 
  this.animation = animation 
  animation.translateY(200).step() 
  this.setData({ 
   animationData: animation.export(), 
  }) 
  setTimeout(function () { 
   animation.translateY(0).step() 
   this.setData({ 
    animationData: animation.export(), 
    showModalStatus: false 
   }) 
  }.bind(this), 200) 
 }, 
})

index.wxml:

<button type="default" bindtap="clickbtn"> 
 点击 
</button> 
<view class="commodity_screen" bindtap="hideModal" wx:if="{{showModalStatus}}"></view> 
<view animation="{{animationData}}" class="commodity_attr_box" wx:if="{{showModalStatus}}"> 
<!--对话框标题--> 
 <view class="title-view"> 
  <view class="toast-view"> 
   要显示的内容 
  </view> 
   
 </view> 
</view>

效果图:

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

Javascript 相关文章推荐
jQuery(js)获取文字宽度(显示长度)示例代码
Dec 31 Javascript
jQuery中的each()详细介绍(推荐)
May 25 Javascript
ajax分页效果(bootstrap模态框)
Jan 23 Javascript
ajax实现加载页面、删除、查看详细信息 bootstrap美化页面!
Mar 14 Javascript
JavaScript之Date_动力节点Java学院整理
Jun 28 Javascript
Bootstrap一款超好用的前端框架
Sep 25 Javascript
微信小程序使用map组件实现检索(定位位置)周边的POI功能示例
Jan 23 Javascript
Vue中全局变量的定义和使用
Jun 05 Javascript
vue远程加载sfc组件思路详解
Dec 25 Javascript
JS面向对象编程实现的拖拽功能案例详解
Mar 03 Javascript
JS绘图Flot如何实现动态可刷新曲线图
Oct 16 Javascript
如何在vue中使用百度地图添加自定义覆盖物(水波纹)
Nov 03 Javascript
JavaScript判断浏览器及其版本信息
Jan 20 #Javascript
JS中传递参数的几种不同方法比较
Jan 20 #Javascript
JS出现失效的情况总结
Jan 20 #Javascript
JSON 数据详解及实例代码分析
Jan 20 #Javascript
Angular ui.bootstrap.pagination分页
Jan 20 #Javascript
bootstrap中的 form表单属性role=&quot;form&quot;的作用详解
Jan 20 #Javascript
javascript容错处理代码(屏蔽js错误)
Jan 20 #Javascript
You might like
PHP中文URL编解码(urlencode()rawurlencode()
2010/07/03 PHP
第4章 数据处理-php正则表达式-郑阿奇(续)
2011/07/04 PHP
深入解析PHP中逗号与点号的区别
2013/08/05 PHP
php使用百度翻译api示例分享
2014/01/31 PHP
php实现获取文件mime类型的方法
2015/02/11 PHP
JavaScript语法着色引擎(demo及打包文件下载)
2007/06/13 Javascript
简略的前端架构心得&amp;&amp;基于editor为例子的编码小技巧
2010/11/25 Javascript
把input初始值不写value的具体实现方法
2013/07/04 Javascript
Firefox中通过JavaScript复制数据到剪贴板(Copy to Clipboard 跨浏览器版)
2013/11/22 Javascript
jQuery中toggle()函数的使用实例
2015/04/17 Javascript
JS+CSS实现仿msn风格选项卡效果代码
2015/10/22 Javascript
JS中常用的正则表达式
2016/09/29 Javascript
微信小程序 地图定位简单实例
2016/10/14 Javascript
js实现碰撞检测特效代码分享
2016/10/16 Javascript
Angular ng-repeat指令实例以及扩展部分
2016/12/26 Javascript
js输入框使用正则表达式校验输入内容的实例
2017/02/12 Javascript
详解Node.js项目APM监控之New Relic
2017/05/12 Javascript
深究AngularJS中ng-drag、ng-drop的用法
2017/06/12 Javascript
node.js实现的装饰者模式示例
2017/09/06 Javascript
Vue多种方法实现表头和首列固定的示例代码
2018/02/02 Javascript
js中document.write和document.writeln的区别
2018/03/11 Javascript
vue axios数据请求get、post方法及实例详解
2018/09/11 Javascript
详解Element 指令clickoutside源码分析
2019/02/15 Javascript
微信公众号H5之微信分享常见错误和问题(小结)
2019/11/14 Javascript
vue与iframe之间的信息交互的实现
2020/04/08 Javascript
python中pygame模块用法实例
2014/10/09 Python
使用NumPy读取MNIST数据的实现代码示例
2019/11/20 Python
Python Django中的STATIC_URL 设置和使用方式
2020/03/27 Python
python实现计算图形面积
2021/02/22 Python
CSS3中box-shadow的用法介绍
2015/07/15 HTML / CSS
如何使用canvas绘制可移动网格的示例代码
2020/12/14 HTML / CSS
香港个人化生活购物网站:Ballyhoo Limited
2016/09/10 全球购物
英国男士时尚网站:Dandy Fellow
2018/02/09 全球购物
俄罗斯园林植物网上商店:Garshinka
2020/07/16 全球购物
本科生职业生涯规划书范文
2014/01/21 职场文书
Vue的生命周期一起来看看
2022/02/24 Vue.js