target.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // compontents/target/target.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. wxObjectives: {
  8. type: String,
  9. value: ""
  10. }
  11. },
  12. /**
  13. * 组件的初始数据
  14. */
  15. data: {
  16. flag: false,
  17. animationData: {},
  18. downUp: '展开'
  19. },
  20. /**
  21. * 组件的方法列表
  22. */
  23. methods: {
  24. onTap (e) {
  25. let flage = e.target.dataset.flag;
  26. if(flage){
  27. this.util(flage, '156rpx');
  28. this.setData({
  29. 'flag': false,
  30. 'downUp': '展开'
  31. })
  32. } else {
  33. this.util(flage, '200rpx');
  34. this.setData({
  35. 'flag': true,
  36. 'downUp': '收起'
  37. })
  38. }
  39. },
  40. /* 创建动画并执行 */
  41. util (flag, height) {
  42. // 创建动画实例
  43. var animation = wx.createAnimation({
  44. duration: 200, //动画时长
  45. timingFunction: "linear", //线性
  46. delay: 0 //0则不延迟
  47. });
  48. this.animation = animation;
  49. animation.height(height).step();
  50. this.setData({
  51. animationData: animation.export()
  52. })
  53. }
  54. }
  55. })