target.js 1.3 KB

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