preview.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // compontents/lesson_list/lessonList.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. materialData: {
  8. type: Array,
  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. const height = this.properties.materialData.length * 65;
  27. if(flage){
  28. this.util(flage, '270rpx');
  29. this.setData({
  30. 'flag': false,
  31. 'downUp': '展开'
  32. })
  33. } else {
  34. this.util(flage, height + 'rpx');
  35. this.setData({
  36. 'flag': true,
  37. 'downUp': '收起'
  38. })
  39. }
  40. },
  41. /* 创建动画并执行 */
  42. util (flag, height) {
  43. // 创建动画实例
  44. var animation = wx.createAnimation({
  45. duration: 200, //动画时长
  46. timingFunction: "linear", //线性
  47. delay: 0 //0则不延迟
  48. });
  49. this.animation = animation;
  50. animation.height(height).step();
  51. this.setData({
  52. animationData: animation.export()
  53. })
  54. }
  55. }
  56. })