金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.0 KiB

  1. export default class Animation {
  2. constructor (id,opts = {},name = 'animation'){
  3. this.id = id;
  4. this.opts = opts;
  5. this.page = getCurrentPages()[getCurrentPages().length - 1];
  6. this.setData = this.page.setData.bind(this.page);
  7. this.animate = wx.createAnimation(Object.assign({
  8. duration:350,
  9. timingFunction:'linear',
  10. delay:0,
  11. },opts));
  12. this.name = name
  13. this.page.data[`${id}.${name}`] = {}
  14. }
  15. up(){
  16. this.animate.translate3d(0,'100%',0).step();
  17. this.setData({
  18. [`${this.id}.${this.name}`] : this.animate.export()
  19. })
  20. return new Promise((resolve,reject) => {setTimeout(() => {resolve()},350)})
  21. }
  22. positionInit () {
  23. this.animate.translate3d(0,'-55px',0).step();
  24. this.setData({
  25. [`${this.id}.${this.name}`] : this.animate.export()
  26. })
  27. }
  28. down(){
  29. this.animate.translate3d(0,'-100%',0).step();
  30. this.setData({
  31. [`${this.id}.${this.name}`] : this.animate.export()
  32. })
  33. }
  34. left(){
  35. this.animate.translate3d('-100%',0,0).step();
  36. this.setData({
  37. [`${this.id}.${this.name}`] : this.animate.export()
  38. })
  39. }
  40. Pullleft(){
  41. this.animate.translate3d(0,0,0).step();
  42. this.setData({
  43. [`${this.id}.${this.name}`] : this.animate.export()
  44. })
  45. }
  46. right(){
  47. this.animate.translate3d('100%',0,0).step();
  48. this.setData({
  49. [`${this.id}.${this.name}`] : this.animate.export()
  50. })
  51. return new Promise((resolve,reject) => {setTimeout(() => {resolve()},350)})
  52. }
  53. expandUp(){
  54. this.animate.height(0).step();
  55. this.setData({
  56. [`${this.id}.${this.name}`] : this.animate.export()
  57. })
  58. }
  59. expandDown(){
  60. this.animate.height('100%').step();
  61. this.setData({
  62. [`${this.id}.${this.name}`] : this.animate.export()
  63. })
  64. }
  65. }