index.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. setTimeout(function () {
  53. animation.translateY(0).step()
  54. this.setData({
  55. animationData: animation.export(),
  56. showModalStatus: false
  57. })
  58. }.bind(this), 200)
  59. },
  60. }
  61. })