运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> #frameDiv { width: 200px; height: 200px; margin: 20px; position: relative; border: solid black 1px; background-color: rgb(205, 242, 205); } #pinkDiv { width: 30px; height: 10px; border-radius: 3px 10px 10px 3px; background-color: hotpink; offset-path: path('M 75,100 C 75,150 150,150 150,100 M 150,100 C 150,50 75,50 75,100'); animation: moveDiv linear 3s infinite; } @keyframes moveDiv { 100% { offset-distance: 100%; } } </style> </head> <body> <h1>Change the offset-path property value with JavaScript</h1> <p>The pink div is animated to follow a path written in SVG syntax.</p> <p>Click the "Try it" button to change the path:</p> <button onclick="myFunction()">Try it</button> <div id="frameDiv"> <div id="pinkDiv"></div> </div> <p>For more information on how to draw an SVG path visit <a href="https://w3schools.org.cn/graphics/svg_path.asp" target="_blank">SVG Tutorial -> SVG Path</a></p> <script> function myFunction() { document.getElementById("pinkDiv").style.offsetPath = "path('M20,170 L100,20 L180,100 Z')"; } </script> </body> </html>