entry.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import * as plugin from 'tailwindcss/plugin.js';
  2. // @ts-expect-error Parameter 'addUtilities' implicitly has an 'any' type.
  3. const enterAnimationPlugin = plugin(({ addUtilities }) => {
  4. const maxChild = 5;
  5. const utilities: Record<string, any> = {};
  6. for (let i = 1; i <= maxChild; i++) {
  7. const baseDelay = 0.1;
  8. const delay = `${baseDelay * i}s`;
  9. utilities[`.enter-x:nth-child(${i})`] = {
  10. animation: `enter-x-animation 0.3s ease-in-out ${delay} forwards`,
  11. opacity: '0',
  12. transform: `translateX(50px)`,
  13. };
  14. utilities[`.enter-y:nth-child(${i})`] = {
  15. animation: `enter-y-animation 0.3s ease-in-out ${delay} forwards`,
  16. opacity: '0',
  17. transform: `translateY(50px)`,
  18. };
  19. utilities[`.-enter-x:nth-child(${i})`] = {
  20. animation: `enter-x-animation 0.3s ease-in-out ${delay} forwards`,
  21. opacity: '0',
  22. transform: `translateX(-50px)`,
  23. };
  24. utilities[`.-enter-y:nth-child(${i})`] = {
  25. animation: `enter-y-animation 0.3s ease-in-out ${delay} forwards`,
  26. opacity: '0',
  27. transform: `translateY(-50px)`,
  28. };
  29. }
  30. // 添加动画关键帧
  31. addUtilities(utilities);
  32. addUtilities({
  33. '@keyframes enter-x-animation': {
  34. to: {
  35. opacity: '1',
  36. transform: 'translateX(0)',
  37. },
  38. },
  39. '@keyframes enter-y-animation': {
  40. to: {
  41. opacity: '1',
  42. transform: 'translateY(0)',
  43. },
  44. },
  45. });
  46. });
  47. export { enterAnimationPlugin };