animate.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { getRect } from '../common/utils';
  2. function useAnimation(context, expanded, mounted, height) {
  3. const animation = wx.createAnimation({
  4. duration: 0,
  5. timingFunction: 'ease-in-out',
  6. });
  7. if (expanded) {
  8. if (height === 0) {
  9. animation.height('auto').top(1).step();
  10. }
  11. else {
  12. animation
  13. .height(height)
  14. .top(1)
  15. .step({
  16. duration: mounted ? 300 : 1,
  17. })
  18. .height('auto')
  19. .step();
  20. }
  21. context.setData({
  22. animation: animation.export(),
  23. });
  24. return;
  25. }
  26. animation.height(height).top(0).step({ duration: 1 }).height(0).step({
  27. duration: 300,
  28. });
  29. context.setData({
  30. animation: animation.export(),
  31. });
  32. }
  33. export function setContentAnimate(context, expanded, mounted) {
  34. getRect(context, '.van-collapse-item__content')
  35. .then((rect) => rect.height)
  36. .then((height) => {
  37. useAnimation(context, expanded, mounted, height);
  38. });
  39. }