target.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. src: '../../pages/image/toUp.png'
  20. },
  21. /**
  22. * 组件的方法列表
  23. */
  24. methods: {
  25. onTap (e) {
  26. let flage = e.target.dataset.flag;
  27. if(flage){
  28. this.util(flage, '156rpx');
  29. this.setData({
  30. 'flag': false,
  31. 'downUp': '展开',
  32. 'src': '../../pages/image/toUp.png'
  33. })
  34. } else {
  35. this.util(flage, '200rpx');
  36. this.setData({
  37. 'flag': true,
  38. 'downUp': '收起',
  39. 'src': '../../pages/image/toDown.png'
  40. })
  41. }
  42. },
  43. /* 创建动画并执行 */
  44. util (flag, height) {
  45. // 创建动画实例
  46. var animation = wx.createAnimation({
  47. duration: 200, //动画时长
  48. timingFunction: "linear", //线性
  49. delay: 0 //0则不延迟
  50. });
  51. this.animation = animation;
  52. animation.height(height).step();
  53. this.setData({
  54. animationData: animation.export()
  55. })
  56. }
  57. }
  58. })