微信小程序 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 相关文章推荐
js 禁止选择功能实现代码(兼容IE/Firefox)
Apr 23 Javascript
javascript Array对象基础知识小结
Nov 16 Javascript
jquery实现点击页面计算点击次数
Jan 23 Javascript
基于jQuery实现左右图片轮播(原理通用)
Dec 24 Javascript
浅谈React和Redux的连接react-redux
Dec 04 Javascript
webpack4的迁移的使用方法
May 25 Javascript
如何使用less实现随机下雪动画详解
Jan 02 Javascript
socket在egg中的使用实例代码详解
May 30 Javascript
ES6的异步终极解决方案分享
Jul 11 Javascript
通过实例了解JS 连续赋值
Sep 24 Javascript
js实现查询商品案例
Jul 22 Javascript
uniapp开发小程序实现滑动页面控制元素的显示和隐藏效果
Dec 10 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验证码(支持中文)
2007/02/14 PHP
PHP url 加密解密函数代码
2011/08/26 PHP
php更新mysql后获取影响的行数发生异常解决方法
2013/03/28 PHP
基于php在各种web服务器的运行模式详解
2013/06/03 PHP
php获取网页里所有图片并存入数组的方法
2015/04/06 PHP
php实现通过cookie换肤的方法
2015/07/13 PHP
PHP实现的二分查找算法实例分析
2017/12/19 PHP
checkbox全选/取消全选以及checkbox遍历jQuery实现代码
2009/12/02 Javascript
Javascript在IE或Firefox下获取鼠标位置的代码
2009/12/18 Javascript
基于jquery的无限级联下拉框js插件
2011/10/29 Javascript
javascript正则表达式基础知识入门
2015/04/20 Javascript
JQuery学习总结【一】
2016/12/01 Javascript
ES6中Array.copyWithin()函数的用法实例详解
2017/09/16 Javascript
解决低版本的浏览器不支持es6的import问题
2018/03/09 Javascript
element ui table(表格)实现点击一行展开功能
2018/12/04 Javascript
python实现忽略大小写对字符串列表排序的方法
2014/09/25 Python
Python的迭代器和生成器使用实例
2015/01/14 Python
pandas数据处理基础之筛选指定行或者指定列的数据
2018/05/03 Python
Python subprocess模块功能与常见用法实例详解
2018/06/28 Python
flask中的wtforms使用方法
2018/07/21 Python
python虚拟环境迁移方法
2019/01/03 Python
对python dataframe逻辑取值的方法详解
2019/01/30 Python
10款最好的Python开发编辑器
2019/07/03 Python
python argparser的具体使用
2019/11/10 Python
解决tensorflow/keras时出现数组维度不匹配问题
2020/06/29 Python
碧欧泉法国官网:Biotherm法国
2019/10/23 全球购物
什么是Assembly(程序集)
2014/09/14 面试题
学期自我鉴定
2013/11/04 职场文书
户外活动策划方案
2014/03/12 职场文书
个人考核材料
2014/05/15 职场文书
动漫设计与制作专业推荐信
2014/07/07 职场文书
大学团日活动新闻稿
2014/09/10 职场文书
校园新闻稿范文
2015/07/18 职场文书
2019年XX公司的晨会制度及流程!
2019/07/23 职场文书
用Python提取PDF表格的方法
2021/04/11 Python
Golang 实现获取当前函数名称和文件行号等操作
2021/05/08 Golang