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

 更新时间:2017年01月20日 17:04:57   投稿:lqh  
这篇文章主要介绍了微信小程序 Toast自定义实例详解的相关资料,需要的朋友可以参考下

微信小程序 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> 

效果图:

源码下载链接:http://xiazai.jb51.net/201701/yuanma/toastTestNew(jb51.net).rar

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

相关文章

  • JS前端绘图canvas模糊问题示例高清图解

    JS前端绘图canvas模糊问题示例高清图解

    这篇文章主要为大家介绍了JS前端绘图canvas模糊问题示例高清图解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-08-08
  • 微信小程序 数组(增,删,改,查)等操作实例详解

    微信小程序 数组(增,删,改,查)等操作实例详解

    这篇文章主要介绍了微信小程序 数组(增,删,改,查)等操作实例详解的相关资料,这里对小程序的数组进行操作,简单实例,需要的朋友可以参考下
    2017-01-01
  • 微信小程序 监听手势滑动切换页面实例详解

    微信小程序 监听手势滑动切换页面实例详解

    这篇文章主要介绍了微信小程序 监听手势滑动切换页面实例详解的相关资料,需要的朋友可以参考下
    2017-06-06
  • Express框架两个内置中间件方法详解

    Express框架两个内置中间件方法详解

    这篇文章主要为大家介绍了Express框架两个内置中间件方法详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-03-03
  • 前端Website sitemap.xml文件搜索引擎优化

    前端Website sitemap.xml文件搜索引擎优化

    这篇文章主要为大家介绍了前端Website的sitemap.xml文件和搜索引擎优化实现详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-05-05
  • Js原型链constructor prototype __proto__属性实例详解

    Js原型链constructor prototype __proto__属性实例详解

    这篇文章主要介绍了Js原型链constructor prototype __proto__属性实例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-10-10
  • window属性onbeforeunload语法教程示例

    window属性onbeforeunload语法教程示例

    这篇文章主要为大家介绍了window属性onbeforeunload语法教程示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-07-07
  • JS前端中的设计模式和使用场景示例详解

    JS前端中的设计模式和使用场景示例详解

    这篇文章主要为大家介绍了JS前端中的设计模式和使用场景示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-08-08
  • 让chatGPT教你如何使用taro创建mbox

    让chatGPT教你如何使用taro创建mbox

    这篇文章主要为大家介绍了让chatGPT教你如何使用taro创建mbox实现实例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-03-03
  • JavaScript中isPrototypeOf函数

    JavaScript中isPrototypeOf函数

    这篇文章主要介绍了JavaScript中isPrototypeOf函数,isPrototypeOf() 是 Object函数(类)的下的一个方法,用于判断当前对象是否为另外一个对象的原型,如果是就返回 true,否则就返回 false,下面来看看详细内容,需要的朋友可以参考一下
    2021-11-11

最新评论