运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> #frameDiv { width: 300px; height: 300px; margin: 20px; position: relative; border: solid black 1px; background-color: rgb(205, 242, 205); } #circleDiv { border: solid darkred 3px; height: 10px; width: 10px; border-radius: 50%; position: absolute; z-index: 2; box-sizing: border-box; offset-path: path('M 50,150 C 50,275 250,275 250,150 M 250,150 C 250,25 50,25 50,150'); animation: moveDiv linear 7s infinite; } svg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } #pinkDiv { position: absolute; background-color: hotpink; opacity: 0.5; z-index: 1; width: 45px; height: 45px; offset-path: path('M 50,150 C 50,275 250,275 250,150 M 250,150 C 250,25 50,25 50,150'); offset-rotate: 0deg; animation: moveDiv linear 7s infinite; } @keyframes moveDiv { 100% { offset-distance: 100%; } } </style> </head> <body> <h1>Change the offset-anchor property value with JavaScript</h1> <p>The pink box is achored to the path so that it is fastened to the path at its center. This is default.</p> <p>Click the "Try it" button to change the achored point to the right bottom corner of the pink box:</p> <button onclick="myFunction()">Try it</button> <div id="frameDiv"> <div id="pinkDiv"></div> <div id="circleDiv"></div> <svg fill="none" stroke="gray" stroke-width="2" stroke-dasharray="5,5"> <path d="M 50,150 C 50,275 250,275 250,150 M 250,150 C 250,25 50,25 50,150" /> </svg> </div> <script> function myFunction() { document.querySelector("#pinkDiv").style.offsetAnchor = "bottom right"; } </script> </body> </html>