index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. Component({
  2. data: {
  3. //弹窗显示控制
  4. showModalStatus: false,
  5. animationData: {},
  6. height: 0
  7. },
  8. lifetimes: {
  9. attached() {
  10. wx.getSystemInfo({
  11. success: (res) => {
  12. this.setData({
  13. height: res.windowHeight * 0.7
  14. })
  15. }
  16. })
  17. }
  18. },
  19. methods: {
  20. //底部弹出框
  21. showModal() {
  22. // 背景遮罩层
  23. var animation = wx.createAnimation({
  24. duration: 200,
  25. timingFunction: "linear",
  26. delay: 0
  27. })
  28. animation.translateY(this.data.height).step()
  29. this.setData({
  30. animationData: animation.export(),
  31. showModalStatus: true
  32. })
  33. setTimeout(function () {
  34. animation.translateY(0).step()
  35. this.setData({
  36. animationData: animation.export()
  37. })
  38. }.bind(this), 200)
  39. },
  40. //点击背景面任意一处时,弹出框隐藏
  41. hideModal: function () {
  42. //弹出框消失动画
  43. var animation = wx.createAnimation({
  44. duration: 200,
  45. timingFunction: "linear",
  46. delay: 0
  47. })
  48. animation.translateY(this.data.height).step()
  49. this.setData({
  50. animationData: animation.export(),
  51. })
  52. this.triggerEvent('close')
  53. setTimeout(function () {
  54. animation.translateY(0).step()
  55. this.setData({
  56. animationData: animation.export(),
  57. showModalStatus: false
  58. })
  59. }.bind(this), 200)
  60. },
  61. }
  62. })