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. console.log(111);
  23. // 背景遮罩层
  24. var animation = wx.createAnimation({
  25. duration: 200,
  26. timingFunction: "linear",
  27. delay: 0
  28. })
  29. animation.translateY(this.data.height).step()
  30. this.setData({
  31. animationData: animation.export(),
  32. showModalStatus: true
  33. })
  34. setTimeout(function () {
  35. animation.translateY(0).step()
  36. this.setData({
  37. animationData: animation.export()
  38. })
  39. }.bind(this), 200)
  40. },
  41. //点击背景面任意一处时,弹出框隐藏
  42. hideModal: function () {
  43. //弹出框消失动画
  44. var animation = wx.createAnimation({
  45. duration: 200,
  46. timingFunction: "linear",
  47. delay: 0
  48. })
  49. animation.translateY(this.data.height).step()
  50. this.setData({
  51. animationData: animation.export(),
  52. })
  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. })