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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <?xml version="1.0" encoding="utf-8"?>
<svg viewBox="0 0 503.15 381.6" xmlns="http://www.w3.org/2000/svg">
  <path id="N_LowerLip" data-name="N LowerLip" d="M 189.23 165.58 C 198.782 168.559 226.921 173.343 248.27 173.19 C 268.248 173.046 288.028 169.201 306.86 162.53 C 298.038 167.592 266.632 177.431 248.39 177.65 C 230.148 177.869 198.278 170.243 189.23 165.58 Z" transform="translate(0 0)" fill="#231f20"/>
  <path id="P_LowerLip" data-name="P LowerLip" d="M 293.76 185.45 C 286.789 180.498 262.23 170.977 246.223 171.39 C 229.308 171.827 206.498 185.696 200.18 191.45 C 205.77 184.739 223.837 168.612 246.108 168.36 C 268.379 168.108 287.385 179.485 293.76 185.45 Z" transform="translate(0 0)" fill="#231f20"/>
</svg>
              
            
!

CSS

              
                
svg {
  display: block;
  margin: 0 auto;
  overflow: visible;
}
body {
  background: #333;
  text-align:center;
  color:#ccc; 
  font-family:Asap, 'sans-serif';
}

button {
  padding:6px;
  font-size:22px;
}
.nav{
   margin:30px;
   font-size:18px;
}


              
            
!

JS

              
                /*
		For use with GreenSock's MorphSVGPlugin - helps find the best-looking shapeIndex value.

		USAGE:
		findShapeIndex("#yourTarget", "#otherShape", {duration:3, ease:"none", size:10});

		You can pass in either the other shape's selector text, or the full path data, like:

		findShapeIndex("#yourTarget", "M506.066,200L400,306.066L293.934,200L400,93.934L506.066,200z", {duration:3, ease:"none", size:10});

		Tap the up/down arrows (or left/right or "u"/"d") to change the shapeIndex.

		Requires: GSAP 3.0.0 (or later), MorphSVGPlugin

		LAST UPDATED: 2019-11-10
		Copyright 2019, GreenSock Inc.
		@author: Jack Doyle, jack@greensock.com
		*/

function findShapeIndex(target, endShape, vars) {
  vars = vars || {};
  var _doc = document,
      _get = function(e) {
        return _doc.querySelectorAll(e);
      },
      _createSVG = function(type, attributes) {
        var element = _doc.createElementNS("http://www.w3.org/2000/svg", type),
            reg = /([a-z])([A-Z])/g,
            p;
        for (p in attributes) {
          element.setAttributeNS(null, p.replace(reg, "$1-$2").toLowerCase(), attributes[p]);
        }
        return element;
      },
      _numExp = /[-+=\.]*\d+[\.e\-\+]*\d*[e\-\+]*\d*/gi, //finds any numbers, including ones that start with += or -=, negative numbers, and ones in scientific notation like 1e-8.
      _selectorExp = /(^[#\.][a-z]|[a-y][a-z])/gi,
      _parseShape = (shape, forcePath, target) => {
        let isString = typeof(shape) === "string",
            e, type;
        if (!isString || _selectorExp.test(shape) || (shape.match(_numExp) || []).length < 3) {
          e = gsap.utils.toArray(shape)[0];
          if (e) {
            type = (e.nodeName + "").toUpperCase();
            if (forcePath && type !== "PATH") { //if we were passed an element (or selector text for an element) that isn't a path, convert it.
              e = MorphSVGPlugin.convertToPath(e, false);
              type = "PATH";
            }
            shape = e.getAttribute(type === "PATH" ? "d" : "points") || "";
            if (e === target) { //if the shape matches the target element, the user wants to revert to the original which should have been stored in the data-original attribute
              shape = e.getAttributeNS(null, "data-original") || shape;
            }
          } else {
            console.warn("Invalid morph to: " + shape);
            shape = false;
          }
        }
        return shape;
      },
      startDot, endDot, incrementButton, decrementButton,
      _setup = function() {
        var e = _doc.createElement("div"),
            label = _doc.createElement("div"),
            body = _get("body")[0];
        incrementButton = _doc.createElement("div");
        decrementButton = _doc.createElement("div");
        label.setAttribute("id", "shapeIndexLabel");
        startDot = _createSVG("circle", {cx:0, cy:0, r:(vars.startStrokeWidth || 3) + 3, fill:vars.startStroke || "red"});
        endDot = _createSVG("circle", {cx:0, cy:0, r:(vars.endStrokeWidth || 3) + 3, fill:vars.endStroke || "yellow"});
        gsap.set(e, {padding:"0px", position:"absolute", bottom:0, fontSize:"20px", textAlign:"center", backgroundColor: "black", color:"#91e600", border:"1px solid #999", left:"50%", xPercent:-50, yPercent:-50, userSelect:"none", fontFamily:"sans-serif", zIndex: 100});
        gsap.set(label, {display:"inline-block", minWidth:"210px", marginRight:"10px", textAlign:"center", marginLeft:"10px"});
        gsap.set([incrementButton, decrementButton], {display:"inline-block", padding:"0 15px", color:"#ccc", height:"50px", lineHeight:"48px", cursor:"pointer"});
        gsap.set(decrementButton, {borderRight:"1px solid #999"});
        gsap.set(incrementButton, {borderLeft:"1px solid #999"});
        decrementButton.innerHTML = " - ";
        incrementButton.innerHTML = " + ";
        e.appendChild(decrementButton);
        e.appendChild(label);
        e.appendChild(incrementButton);
        if (body) {
          body.appendChild(e);
        }
        return label;
      },
      label = _get("#shapeIndexLabel")[0] || _setup(),
      index = 0,
      _yoyo = function() {
        shapeTween.reversed(!shapeTween.reversed()).resume();
        dotTween.reversed(!dotTween.reversed()).resume();
      },
      shapeTween,	dotTween, startBezier, endBezier,
      dotProxy = {x:0, y:0},
      _getFirstCoordinates = function(start, end, shapeIndex) {
        startBezier = MorphSVGPlugin.stringToRawPath(start);
        endBezier = MorphSVGPlugin.stringToRawPath(end);

        MorphSVGPlugin.equalizeSegmentQuantity(startBezier, endBezier, shapeIndex);
        return [startBezier[0][0], startBezier[0][1], endBezier[0][0], endBezier[0][1]];
      },
      _startTween = function() {
        var coordinates = _getFirstCoordinates(origStartShape, origEndShape, index);
        dotProxy.x = coordinates[0];
        dotProxy.y = coordinates[1];
        startDot.setAttribute("cx", dotProxy.x);
        startDot.setAttribute("cy", dotProxy.y);
        endDot.setAttribute("cx", coordinates[2]);
        endDot.setAttribute("cy", coordinates[3]);
        shapeTween = gsap.fromTo(target, {morphSVG: origStartShape}, {delay:0.5, duration:vars.duration || 3, morphSVG:{shape:origEndShape, shapeIndex:index}, ease:vars.ease || "none", onComplete:_yoyo, onReverseComplete:_yoyo, overwrite:true});
        dotTween = gsap.to(dotProxy, {delay:0.5, duration:vars.duration || 3, x:coordinates[2], y:coordinates[3], ease:vars.ease || "none", onUpdate:function() {
          startDot.setAttribute("cx", dotProxy.x);
          startDot.setAttribute("cy", dotProxy.y);
        }});
      },
      _refresh = function() {
        label.innerHTML = "shapeIndex: " +  index + (index === autoIndex ? " (auto)" : "");
        shapeTween.seek(0).kill();
        dotTween.seek(0).kill();
        _startTween();
        gsap.fromTo(label.parentNode, 0.4, {backgroundColor:"#777"}, {backgroundColor:"black", ease:"none"});
      },
      _increment = function() {
        index = (index + 1) % (maxIndex + 1);
        _refresh();
      },
      _decrement = function() {
        index = (index - 1) % (maxIndex + 1);
        _refresh();
      },
      autoIndex,	maxIndex, endTarget;
  if (typeof(target) === "string") {
    target = gsap.utils.toArray(target)[0];
  }
  if (!target) {
    console.log("ERROR: target not found for findShapeIndex(). Please use a valid target.");
    return;
  } else if (target.nodeName && target.nodeName.toUpperCase() !== "PATH") {
    console.log("ERROR: target of findShapeIndex() must be a path.");
    return;
  } else if (target.push && target[0] && target[0].nodeName) {
    target = target[0];
  }
  if (target.parentNode) {
    target.parentNode.appendChild(endDot);
    target.parentNode.appendChild(startDot);
  }
  if (typeof(endShape) !== "string" || (endShape.match(_numExp) || []).length < 3) {
    endTarget = gsap.utils.toArray(endShape);
    if (endTarget && endTarget[0]) {
      endTarget = endTarget[0];
      gsap.set(endTarget, {display:"block", strokeWidth:vars.endStrokeWidth || 3, stroke:vars.endStroke || "yellow", fill:vars.endFill || "none", visibility:"visible", opacity:vars.endOpacity || 0.7});
    }
  }
  gsap.set(target, {display:"block", strokeWidth:vars.startStrokeWidth || 3, stroke:vars.startStroke || "red", fill:vars.startFill || "none", visibility:"visible", opacity:vars.startOpacity || 0.7});
  startBezier = MorphSVGPlugin.stringToRawPath(target.getAttribute("d"));
  endBezier = MorphSVGPlugin.stringToRawPath(_parseShape(endShape, true));
  autoIndex = index = Math.round(MorphSVGPlugin.equalizeSegmentQuantity(startBezier, endBezier, "auto")[0]); //also handles subdividing!
  maxIndex = (startBezier[0].length / 6) | 0;
  gsap.killTweensOf([target, endShape]); //kill other tweens so they don't interfere with our yoyo-ing one.

  const origStartShape = _parseShape(target, true);
  const origEndShape = _parseShape(endShape, true);
  _startTween();
  label.innerHTML = "shapeIndex: " +  index + (index === autoIndex ? " (auto)" : "");
  window.addEventListener("keydown", function(event) {
    var key = event.keyCode;
    if (key === 38 || key === 39 || key === 85) { //right or up arrows (increment)
      _increment();
    } else if (key === 37 || key === 40 || key === 68) { //left or down arrows (decrement)
      _decrement();
    }
  });
  incrementButton.addEventListener("click", _increment);
  decrementButton.addEventListener("click", _decrement);
}

gsap.to("#N_LowerLip", {duration: 3, morphSVG:{shape:"#P_LowerLip", shapeIndex:5}});
//comment out next line to disable findShapeIndex() UI
findShapeIndex("#N_LowerLip", "#P_LowerLip");
              
            
!
999px

Console