CodeLab
Tutorials For Everyone
Run
<!DOCTYPE html> <html> <head> <style> #container { width: 330px; height: 180px; margin: auto; position: relative; box-shadow: 0 0 10px 0 #aaa; background: #333; } #circle { border: solid red 10px; height: 10px; width: 10px; border-radius: 50%; position: absolute; z-index: 2; box-sizing: border-box; offset-path: path('M 30 80 L 300 80'); animation: circle-anim 5s infinite; } #block { position: absolute; width: 50px; height: 50px; background: blue; z-index: 1; offset-path: path('M 30 80 L 300 80'); offset-anchor: bottom left; animation: anchor-anim 5s infinite; overflow: visible; } svg { position: absolute; height: 100%; width: 100%; left: 0; top: 0; } @keyframes anchor-anim { 0% { offset-distance: 0%; offset-anchor: bottom left; } 50% { offset-distance: 100%; offset-anchor: top left; } 100% { offset-distance: 0%; offset-anchor: bottom left; } } @keyframes circle-anim { 0% { offset-distance: 0%; } 50% { offset-distance: 100%; } 100% { offset-distance: 0%; } } </style> </head> <body> <h1>Animatable 'offset-anchor' Property</h1> <hr> <p>The blue element is first "anchored" to the path at the bottom left corner point. Within 5 seconds the achored point is moved to the top left corner of the blue box.</p> <div id="container"> <div id="block"></div> <div id="circle"></div> <svg> <path d="M 30 80 L 300 80" fill="none" stroke="white" stroke-width="2" stroke-dasharray="5,5"/> </svg> </div> </body> </html>