| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>SVG Mask Reveal - Animal.js</title>
- <link rel="stylesheet" href="../demo.css">
- <style>
- .demo-visual {
- padding: 26px 30px;
- background: #151515;
- display: grid;
- grid-template-columns: 1fr 280px;
- gap: 16px;
- }
- .stage {
- background: #000;
- border: 1px solid #262626;
- border-radius: 12px;
- padding: 0;
- overflow: hidden;
- min-height: 240px;
- display: grid;
- place-items: center;
- position: relative;
- }
- .panel {
- background: rgba(0,0,0,0.18);
- border: 1px solid #262626;
- border-radius: 12px;
- padding: 14px;
- display: flex;
- flex-direction: column;
- gap: 12px;
- }
- svg { width: 100%; height: 100%; position: absolute; top:0; left:0; }
-
- .bg-image {
- width: 100%; height: 100%;
- object-fit: cover;
- opacity: 0.5;
- }
- .reveal-text {
- fill: #fff;
- font-size: 40px;
- font-weight: 900;
- text-anchor: middle;
- letter-spacing: 4px;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <div class="page-top">
- <div class="crumb">ANIMATION › SVG</div>
- <div class="since">SINCE 1.0.0</div>
- </div>
- <h1>SVG Mask Reveal</h1>
- <p class="description">使用 SVG <code class="inline"><mask></code> 制作遮罩动画。可以控制遮罩内的图形形状、位置、大小来揭示内容。</p>
- <div class="box-container">
- <div class="demo-visual">
- <div class="stage">
- <img src="https://images.unsplash.com/photo-1492144534655-ae79c964c9d7?auto=format&fit=crop&w=800&q=80" class="bg-image" alt="Background">
-
- <svg viewBox="0 0 400 300" preserveAspectRatio="xMidYMid slice">
- <defs>
- <mask id="myMask">
- <rect width="100%" height="100%" fill="white" />
- <circle id="maskCircle" cx="200" cy="150" r="0" fill="black" />
- </mask>
- </defs>
- <rect width="100%" height="100%" fill="black" mask="url(#myMask)" opacity="0.8" />
- <text x="200" y="165" class="reveal-text" mask="url(#myMask)">REVEAL</text>
- </svg>
- </div>
- <div class="panel">
- <button class="play-btn" onclick="runDemo()">REPLAY</button>
- </div>
- </div>
- </div>
- <script src="../page_utils.js"></script>
- <script src="../../xjs.js"></script>
- <script>
- function runDemo() {
- // Reset
- xjs('#maskCircle').animate({ r: 0, duration: 0 });
-
- // Animate radius to reveal
- xjs('#maskCircle').animate({
- r: [0, 300],
- duration: 2000,
- easing: 'ease-in-out',
- direction: 'alternate',
- loop: true
- });
- }
- setTimeout(runDemo, 320);
- </script>
- </div>
- </body>
- </html>
|