Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <svg viewBox="-70 -200 140 400" id="svg">  
<path fill="SeaShell"
        d="M-50,-50 A50,50,0 0 1 50,-50V50A50,50,0 0 1 -50,50V-50" />

  <!--top-->
<path id="thePath" fill="#4a4a4a"  d="M-44.2932,-50C-44.293,-73.8,-23.8,-93.093,0,-93.093C23.8,-93.093,43.093,-73.8,43.0932,-50C43.093,-26.2,23.2,-50,-0.6,-50C-24.4,-50,-44.293,-26.2,-44.2932,-50z"/>
  
  <text fill="SeaShell" id="up" y="-150">UP</text> 
  <text fill="#808080" id="down" y="150">DOWN</text> 
</svg>

              
            
!

CSS

              
                body{background: #4a4a4a;
    font: 100%/1.5em "Lato", sans-serif;}

svg{
  width:70px;
  position:absolute;
  margin:auto;
  top:0;bottom:0;left:0;right:0; 
  /*border:1px solid;*/
}

text{
  font-size:40px;
  text-anchor:middle;
  dominant-baseline:middle;  
  transition:fill .5s;
}
              
            
!

JS

              
                /*path middle*/
var m = [
  ["M", -36.911, 0],
  ["C", -36.911, -19.833, -19.833, -35.911, 0, -35.911],
  ["C", 19.833, -35.911, 35.911, -19.833, 35.911, 0],
  ["C", 35.911, 19.833, 19.833, 35.911, 0, 35.911],
  ["C", -19.833, 35.911, -36.911, 19.833, -36.911, 0],
  ["z"]
];

var t = [
  /*path top*/
  ["M", -44.2932, -50],
  ["C", -44.293, -73.8, -23.8, -93.093, 0, -93.093],
  ["C", 23.8, -93.093, 43.093, -73.8, 43.0932, -50],
  ["C", 43.093, -26.2, 23.2, -50, -0.6, -50],
  ["C", -24.4, -50, -44.293, -26.2, -44.2932, -50],
  ["z"]
];

var b = [
  /*path bottom*/
  ["M", -44.2932, 50],
  ["C", -44.2932, 26.2, -24.4, 50, -0.6, 50],
  ["C", 23.2, 50, 43.0932, 26.2, 43.093, 50],
  ["C", 43.093, 73.8, 23.8, 93.093, 0, 93.093],
  ["C", -23.8, 93.0932, -44.2932, 73.8, -44.2932, 50],
  ["z"]
];
 
let flag = true;
let rid = null;// the request animation id
let shapes = ["t", "m", "b"];// the array of the shapes names

let actualShape = shapes[0];
let nextShape = shapes[1];

let target;
let vals;

function morph() {
  //the value of the new d attribute for the path
  let newD = "";

  vals.map((v, vi) => {
    let newStr = v[0];
    for (let i = 1; i < v.length; i++) {
      updateProp(vi, i);

      newStr += v[i].toFixed(3) + " ";
    }
    newD += newStr + " ";
  }); 
  thePath.setAttributeNS(null, "d", newD);
}

function updateProp(vi, i) {
  let dist = target[vi][i] - vals[vi][i];
  let vel = dist / 10;
  vals[vi][i] += vel;

  // if the distance in y is less than 1 stop the animation
  let dist_y = target[0][2] - vals[0][2];
  if (Math.abs(dist_y) < 1) {
    if (rid) {
      window.cancelAnimationFrame(rid);
      rid = null;
      // if the flag is true a new animation can begin
      flag = true;
    }
  }
}

let i = 0;// a counter to be increased with every click
svg.addEventListener("click", () => {
  
  //if flag is true set the vals and the target and call the function Frame
  if (flag == true) {
  
  //--------------
  //decide the next shape
  i++;

  nextShape = shapes[i % 3];

  if (i % 2 == 0) {
    shapes.reverse();
    i = 0;
  }
  //-------------
    
    vals = window[actualShape].map(function(arr) {
      return arr.slice();
    });

    target = window[nextShape].map(function(arr) {
      return arr.slice();
    });

    Frame();
    flag = false;
    
    actualShape = nextShape;
  }
});

function Frame() {
  rid = window.requestAnimationFrame(Frame);
  morph();
  
  /*---Text color-----*/
  if(nextShape == "t"){up.style.fill = "SeaShell";down.style.fill = "#808080"}
  if(nextShape == "m"){up.style.fill = "#808080";down.style.fill = "#808080"}
  if(nextShape == "b"){up.style.fill = "#808080";down.style.fill = "SeaShell"}
  /*------------------*/
}
              
            
!
999px

Console