Get your own website Result Size: 625 x 565
x
 
<!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://www.w3schools.com/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')";