test_mask_reveal.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>SVG Mask Reveal - Animal.js</title>
  7. <link rel="stylesheet" href="../demo.css">
  8. <style>
  9. .demo-visual {
  10. padding: 26px 30px;
  11. background: #151515;
  12. display: grid;
  13. grid-template-columns: 1fr 280px;
  14. gap: 16px;
  15. }
  16. .stage {
  17. background: #000;
  18. border: 1px solid #262626;
  19. border-radius: 12px;
  20. padding: 0;
  21. overflow: hidden;
  22. min-height: 240px;
  23. display: grid;
  24. place-items: center;
  25. position: relative;
  26. }
  27. .panel {
  28. background: rgba(0,0,0,0.18);
  29. border: 1px solid #262626;
  30. border-radius: 12px;
  31. padding: 14px;
  32. display: flex;
  33. flex-direction: column;
  34. gap: 12px;
  35. }
  36. svg { width: 100%; height: 100%; position: absolute; top:0; left:0; }
  37. .bg-image {
  38. width: 100%; height: 100%;
  39. object-fit: cover;
  40. opacity: 0.5;
  41. }
  42. .reveal-text {
  43. fill: #fff;
  44. font-size: 40px;
  45. font-weight: 900;
  46. text-anchor: middle;
  47. letter-spacing: 4px;
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <div class="container">
  53. <div class="page-top">
  54. <div class="crumb">ANIMATION › SVG</div>
  55. <div class="since">SINCE 1.0.0</div>
  56. </div>
  57. <h1>SVG Mask Reveal</h1>
  58. <p class="description">使用 SVG <code class="inline">&lt;mask&gt;</code> 制作遮罩动画。可以控制遮罩内的图形形状、位置、大小来揭示内容。</p>
  59. <div class="box-container">
  60. <div class="demo-visual">
  61. <div class="stage">
  62. <img src="https://images.unsplash.com/photo-1492144534655-ae79c964c9d7?auto=format&fit=crop&w=800&q=80" class="bg-image" alt="Background">
  63. <svg viewBox="0 0 400 300" preserveAspectRatio="xMidYMid slice">
  64. <defs>
  65. <mask id="myMask">
  66. <rect width="100%" height="100%" fill="white" />
  67. <circle id="maskCircle" cx="200" cy="150" r="0" fill="black" />
  68. </mask>
  69. </defs>
  70. <rect width="100%" height="100%" fill="black" mask="url(#myMask)" opacity="0.8" />
  71. <text x="200" y="165" class="reveal-text" mask="url(#myMask)">REVEAL</text>
  72. </svg>
  73. </div>
  74. <div class="panel">
  75. <button class="play-btn" onclick="runDemo()">REPLAY</button>
  76. </div>
  77. </div>
  78. </div>
  79. <script src="../page_utils.js"></script>
  80. <script src="../../xjs.js"></script>
  81. <script>
  82. function runDemo() {
  83. // Reset
  84. xjs('#maskCircle').animate({ r: 0, duration: 0 });
  85. // Animate radius to reveal
  86. xjs('#maskCircle').animate({
  87. r: [0, 300],
  88. duration: 2000,
  89. easing: 'ease-in-out',
  90. direction: 'alternate',
  91. loop: true
  92. });
  93. }
  94. setTimeout(runDemo, 320);
  95. </script>
  96. </div>
  97. </body>
  98. </html>