animation.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. Page({
  2. onShareAppMessage() {
  3. return {
  4. title: '动画',
  5. path: 'packageAPI/pages/page/animation/animation',
  6. containerStyle1: '',
  7. }
  8. },
  9. data: {
  10. theme: 'light',
  11. canIUse: true,
  12. },
  13. onLoad() {
  14. this.setData({
  15. theme: wx.getSystemInfoSync().theme || 'light'
  16. })
  17. if (wx.onThemeChange) {
  18. wx.onThemeChange(({theme}) => {
  19. this.setData({theme})
  20. })
  21. }
  22. const canIUse = this.animate !== undefined
  23. if (!canIUse) {
  24. wx.showModal({
  25. title: '微信版本过低,暂不支持本功能',
  26. })
  27. this.setData({
  28. canIUse,
  29. })
  30. }
  31. },
  32. change() {
  33. this.animate('#container1', [
  34. {opacity: 1.0, rotate: 0, backgroundColor: '#FF0000'},
  35. {
  36. opacity: 0.5, rotate: 45, backgroundColor: '#00FF00', offset: 0.9
  37. },
  38. {opacity: 0.0, rotate: 90, backgroundColor: '#FF0000'},
  39. ], 5000, function () {
  40. this.clearAnimation('#container1', {opacity: true, rotate: true}, function () {
  41. console.log('清除了#container上的动画属性')
  42. })
  43. }.bind(this))
  44. this.animate('.block1', [
  45. {scale: [1, 1], rotate: 0, ease: 'ease-out'},
  46. {
  47. scale: [1.5, 1.5], rotate: 45, ease: 'ease-in', offset: 0.9
  48. },
  49. {scale: [2, 2], rotate: 90},
  50. ], 5000, function () {
  51. this.clearAnimation('.block1', {scale: true, rotate: true}, function () {
  52. console.log('清除了.block1上的动画属性')
  53. })
  54. }.bind(this))
  55. },
  56. })