animation.js 986 B

123456789101112131415161718192021222324252627282930313233
  1. function toggleRemindWithAnimation(page, {
  2. remindKey = 'IsShowRemind',
  3. animationKey = 'remindAnimation',
  4. duration = 300,
  5. showAnimation = 'remind-slide-up',
  6. hideAnimation = 'remind-slide-down'
  7. } = {}) {
  8. // 获取当前显示状态
  9. const isCurrentlyShown = page.data[remindKey];
  10. if (isCurrentlyShown) {
  11. // 如果当前是显示状态,先播放隐藏动画,然后再隐藏
  12. const animationData = {};
  13. animationData[animationKey] = hideAnimation;
  14. page.setData(animationData);
  15. // 等待动画完成后再隐藏弹窗
  16. setTimeout(function() {
  17. const hideData = {};
  18. hideData[remindKey] = false;
  19. page.setData(hideData);
  20. }, duration);
  21. } else {
  22. // 如果当前是隐藏状态,直接显示并播放显示动画
  23. const showData = {};
  24. showData[remindKey] = true;
  25. showData[animationKey] = showAnimation;
  26. page.setData(showData);
  27. }
  28. }
  29. module.exports = {
  30. toggleRemindWithAnimation:toggleRemindWithAnimation,
  31. }