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


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 对象模型 执行模型
Oct 15 Javascript
一行代码实现纯数据json对象的深度克隆实现思路
Jan 09 Javascript
通过上下左右键和回车键切换光标实现代码
Mar 08 Javascript
Javascript表单验证要注意的事项
Sep 29 Javascript
基于jQuery滑动杆实现购买日期选择效果
Sep 15 Javascript
JavaScript学习总结之JS、AJAX应用
Jan 29 Javascript
bootstrap vue.js实现tab效果
Feb 07 Javascript
js禁止表单重复提交
Aug 29 Javascript
Vue实现textarea固定输入行数与添加下划线样式的思路详解
Jun 28 Javascript
通过javascript实现扫雷游戏代码实例
Feb 09 Javascript
JavaScript this关键字指向常用情况解析
Sep 02 Javascript
js实现点击烟花特效
Oct 14 Javascript
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
浅析PHP Socket技术
2013/08/02 PHP
ThinkPHP后台首页index使用frameset时的注意事项分析
2014/08/22 PHP
PHP封装分页函数实现文本分页和数字分页
2014/10/23 PHP
php去掉文件前几行的方法
2015/07/29 PHP
UTF-8正则表达式如何匹配汉字
2015/08/03 PHP
PHP实现一个简单url路由功能实例
2016/11/05 PHP
JavaScript var声明变量背后的原理示例解析
2013/10/12 Javascript
javascript教程之不完整的继承(js原型链)
2014/01/13 Javascript
jQuery的css()方法用法实例
2014/12/24 Javascript
jQuery提示插件alertify使用指南
2015/04/21 Javascript
Linux下为Node.js程序配置MySQL或Oracle数据库的方法
2016/03/19 Javascript
微信小程序 UI与容器组件总结
2017/02/21 Javascript
利用Node.js对文件进行重命名
2017/03/12 Javascript
vue-router 中router-view不能渲染的解决方法
2017/05/23 Javascript
nodejs mysql 实现分页的方法
2017/06/06 NodeJs
vue router自动判断左右翻页转场动画效果
2017/10/10 Javascript
使用puppeteer破解极验的滑动验证码
2018/02/24 Javascript
原生JS实现自定义下拉单选选择框功能
2018/10/12 Javascript
详解Vue3.0 前的 TypeScript 最佳入门实践
2019/06/18 Javascript
原生javascript制作的拼图游戏实现方法详解
2020/02/23 Javascript
Ant Design的Table组件去除
2020/10/24 Javascript
Python request设置HTTPS代理代码解析
2018/02/12 Python
Python3利用Dlib19.7实现摄像头人脸识别的方法
2018/05/11 Python
python 文件转成16进制数组的实例
2018/07/09 Python
树莓派升级python的具体步骤
2020/07/05 Python
python实现邮件循环自动发件功能
2020/09/11 Python
Django框架请求生命周期实现原理
2020/11/13 Python
python 根据列表批量下载网易云音乐的免费音乐
2020/12/03 Python
乌克兰机票、铁路和巴士票、酒店搜索、保险:Tickets.ua
2020/01/11 全球购物
内科护士实习自我鉴定
2013/10/17 职场文书
应用心理学个人求职信范文
2013/12/11 职场文书
写给女生的道歉信
2014/01/14 职场文书
工作态度恶劣检讨书
2015/05/06 职场文书
英文辞职信范文
2015/05/13 职场文书
银行客户经理培训心得体会
2016/01/09 职场文书
idea编译器vue缩进报错问题场景分析
2021/07/04 Vue.js