微信小程序 自定义对话框实例详解


Posted in Javascript onJanuary 20, 2017

微信小程序 自定义对话框实例详解

效果图:

微信小程序 自定义对话框实例详解

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="dialog-title"> 
 请输入内容 
</view> 
<!--对话框输入部分--> 
<view class="input-view"> 
 <input type="text" bindblur="input_content" class="input-style"/> 
</view> 
<!--对话框按钮--> 
<view class="line-top">  
</view> 
<view class="btn-view"> 
 <view class="btn-cancel" bindtap="click_cancel">  
     取 消 
 </view> 
 <view class="btn-line"> 
 </view> 
 <view class="btn-cancel" bindtap="click_ok">  
     确 定 
 </view> 
</view> 
</view>

index.js:

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(300).step() 
  this.setData({ 
   animationData: animation.export(), 
   showModalStatus: true 
  }) 
  setTimeout(function () { 
   animation.translateY(0).step() 
   this.setData({ 
    animationData: animation.export() 
   }) 
  }.bind(this), 200) 
 }, 
 clickbtn:function(){ 
  if(this.data.showModalStatus){ 
   this.hideModal(); 
  }else{ 
   this.showModal(); 
  } 
 }, 
 hideModal: function () { 
  // 隐藏遮罩层 
  var animation = wx.createAnimation({ 
   duration: 200, 
   timingFunction: "linear", 
   delay: 0 
  }) 
  this.animation = animation 
  animation.translateY(300).step() 
  this.setData({ 
   animationData: animation.export(), 
  }) 
  setTimeout(function () { 
   animation.translateY(0).step() 
   this.setData({ 
    animationData: animation.export(), 
    showModalStatus: false 
   }) 
  }.bind(this), 200) 
 }, 
 click_cancel:function(){ 
  console.log("点击取消"); 
   this.hideModal(); 
 }, 
 click_ok:function(){ 
  console.log("点击了确定===,输入的信息为为==",inputinfo); 
   this.hideModal(); 
 }, 
 input_content:function(e){ 
  console.log(e); 
  inputinfo = e.detail.value;  
 } 
 
})

源码下载:http://xiazai.3water.com/201701/yuanma/modalTest(3water.com).rar

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

Javascript 相关文章推荐
javascript实现的listview效果
Apr 28 Javascript
childNodes.length与children.length的区别
May 14 Javascript
js word表格动态添加代码
Jun 07 Javascript
修复IE9&amp;safari 的sort方法
Oct 21 Javascript
js格式化货币数据实现代码
Sep 04 Javascript
JS事件在IE与FF中的区别详细解析
Nov 20 Javascript
移除AngularJS下URL中的#字符的方法
Jun 19 Javascript
Bootstrap每天必学之进度条
Nov 30 Javascript
AngularJS  $on、$emit和$broadcast的使用
Sep 05 Javascript
vue生成token并保存到本地存储中
Jul 17 Javascript
详解async/await 异步应用的常用场景
May 13 Javascript
vue特效之翻牌动画
Apr 20 Vue.js
Vue实例简单方法介绍
Jan 20 #Javascript
微信小程序 Toast自定义实例详解
Jan 20 #Javascript
JavaScript判断浏览器及其版本信息
Jan 20 #Javascript
JS中传递参数的几种不同方法比较
Jan 20 #Javascript
JS出现失效的情况总结
Jan 20 #Javascript
JSON 数据详解及实例代码分析
Jan 20 #Javascript
Angular ui.bootstrap.pagination分页
Jan 20 #Javascript
You might like
本地机apache配置基于域名的虚拟主机详解
2013/08/10 PHP
PHPCMS2008广告模板SQL注入漏洞修复
2016/10/11 PHP
srcElement表格样式
2006/09/03 Javascript
基于jquery实现的文字向上跑动类似跑马灯的效果
2014/06/17 Javascript
JS+CSS实现自动切换的网页滑动门菜单效果代码
2015/09/14 Javascript
非常漂亮的相册集 使用jquery制作相册集
2016/04/28 Javascript
微信小程序 生命周期详解
2016/10/12 Javascript
基于jQuery实现滚动切换效果
2016/12/02 Javascript
JS正则表达式判断有效数实例代码
2017/03/13 Javascript
jQuery插件select2利用ajax高效查询大数据列表(可搜索、可分页)
2017/05/19 jQuery
解决iView Table组件宽度只变大不变小的问题
2020/11/13 Javascript
[06:07]DOTA2-DPC中国联赛 正赛 Ehome vs VG 选手采访
2021/03/11 DOTA
在Windows8上的搭建Python和Django环境
2014/07/03 Python
Python获取任意xml节点值的方法
2015/05/05 Python
python统计cpu利用率的方法
2015/06/02 Python
django中的setting最佳配置小结
2017/11/21 Python
Python编程使用*解包和itertools.product()求笛卡尔积的方法
2017/12/18 Python
利用Python将文本中的中英文分离方法
2018/10/31 Python
python绘制地震散点图
2019/06/18 Python
Python 数据可视化pyecharts的使用详解
2019/06/26 Python
对YOLOv3模型调用时候的python接口详解
2019/08/26 Python
Python常驻任务实现接收外界参数代码解析
2020/07/21 Python
使用html5新特性轻松监听任何App自带返回键的示例
2018/03/13 HTML / CSS
美国批发零售网站:GearXS
2016/07/26 全球购物
专门经营化妆刷的美国彩妆品牌:Sigma Beauty
2017/09/11 全球购物
Aquatalia官网:意大利著名鞋履品牌
2019/09/26 全球购物
C++如何引用一个已经定义过的全局变量
2014/08/25 面试题
计算机网络专业求职信
2014/06/05 职场文书
党支部群众路线整改措施思想汇报
2014/10/10 职场文书
刑事和解协议书范本
2014/11/19 职场文书
2015年班主任个人工作总结
2015/03/31 职场文书
三八妇女节主持词
2015/07/04 职场文书
2015年高三毕业班班主任工作总结
2015/10/22 职场文书
python实现图片批量压缩
2021/04/24 Python
浅谈如何提高PHP代码的质量
2021/05/28 PHP
《辉夜大小姐想让我告白》第三季正式预告
2022/03/20 日漫