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


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 相关文章推荐
JS宝典学习笔记(下)
Jan 10 Javascript
全面解析Bootstrap中scrollspy(滚动监听)的使用方法
Jun 06 Javascript
JQuery 动态生成Table表格实例代码
Dec 02 Javascript
微信小程序图片选择、上传到服务器、预览(PHP)实现实例
May 11 Javascript
jquery获取链接地址和跳转详解(推荐)
Aug 15 jQuery
分享vue.js devtools遇到一系列问题
Oct 24 Javascript
vue使用自定义icon图标的方法
May 14 Javascript
详解vue中使用axios对同一个接口连续请求导致返回数据混乱的问题
Nov 06 Javascript
vue实现瀑布流组件滑动加载更多
Mar 10 Javascript
jQuery弹框插件使用方法详解
May 26 jQuery
微信小程序实现列表左右滑动
Nov 19 Javascript
在Vue中使用mockjs代码实例
Nov 25 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
ThinkPHP验证码使用简明教程
2014/03/05 PHP
php实现简单的语法高亮函数实例分析
2015/04/27 PHP
PHP实现的随机IP函数【国内IP段】
2016/07/20 PHP
Zend Framework过滤器Zend_Filter用法详解
2016/12/09 PHP
kindeditor 加入七牛云上传的实例讲解
2017/11/12 PHP
浅谈PHP中pack、unpack的详细用法
2018/03/12 PHP
PHP如何将图片文件上传到另外一台服务器上
2019/08/26 PHP
Yii Framework框架开发微信公众平台示例
2020/04/26 PHP
Javascript在IE下设置innerHTML时出现未知的运行时错误的解决方法
2011/01/12 Javascript
JavaScript中的style.display属性操作
2013/03/27 Javascript
使用简洁的jQuery方法实现隔行换色功能
2014/01/02 Javascript
Node.js与PHP、Python的字符处理性能对比
2014/07/06 Javascript
javascript实现网站加入收藏功能
2015/12/16 Javascript
酷炫jQuery全屏3D焦点图动画效果
2016/03/22 Javascript
Bootstrap select下拉联动(jQuery cxselect)
2017/01/04 Javascript
详解webpack2+node+react+babel实现热加载(hmr)
2017/08/24 Javascript
微信小程序实现滚动消息通知
2018/02/02 Javascript
vue自定义filters过滤器
2018/04/26 Javascript
Element-UI中Upload上传文件前端缓存处理示例
2019/02/21 Javascript
Vue CLI2升级至Vue CLI3的方法步骤
2019/05/20 Javascript
Vue-cli3项目引入Typescript的实现方法
2019/10/18 Javascript
Python爬取附近餐馆信息代码示例
2017/12/09 Python
selenium python浏览器多窗口处理代码示例
2018/01/15 Python
python如何派生内置不可变类型并修改实例化行为
2018/03/21 Python
Pandas之drop_duplicates:去除重复项方法
2018/04/18 Python
这可能是最好玩的python GUI入门实例(推荐)
2019/07/19 Python
在python3中实现查找数组中最接近与某值的元素操作
2020/02/29 Python
PyQt5中QSpinBox计数器的实现
2021/01/18 Python
Django中template for如何使用方法
2021/01/31 Python
美国正宗奢华复古手袋、珠宝及配饰网站:What Goes Around Comes Around
2018/07/21 全球购物
新西兰购物网站:TheMarket NZ
2020/09/19 全球购物
外贸专业求职信
2014/03/09 职场文书
陈安之励志演讲稿
2014/08/21 职场文书
法定代表人资格证明书
2014/09/11 职场文书
开国大典观后感
2015/06/04 职场文书
Python OpenCV快速入门教程
2021/04/17 Python