Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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 xmlns="http://www.w3.org/2000/svg" viewBox="0 0 415.39 264.34">
	<path id="end1" class="cls-1" d="M170.14,202.73c-13.5-11.33-60.83-48-109.58-50.71a53.89,53.89,0,0,0-5.71-.31C24.74,151.71.33,176.92.33,208s24.41,56.32,54.52,56.32c19.32,0,36.24-10.4,45.93-26l0,.05C116,213.09,134.48,200,172,205.82Z"/>
	<path id="start1" class="cls-1" d="M0,207.78a55,55,0,1,1,17.31,40.05A54.84,54.84,0,0,1,0,207.78Z"/>

</svg>
              
            
!

CSS

              
                body {
  margin: 0;
  background: #000;
}
svg {
  display: block;
  margin:0 auto;
  width:600px;
  fill:#ccc;
}
#end1 {
  visibility:hidden;
}
              
            
!

JS

              
                TweenMax.to("#start1", 1.5, {delay:.25, 
  morphSVG:{
    shape:"#end1", 
    origin:"51% 75%,48% 66%", 
    type: "rotational",
    shapeIndex:[-5]
  }
});

// findShapeIndex("#start1", "#end1");
// findMorphOrigin("#start1", "#end1", {showLines:true});

//findMorphOrigin(".bird", ".dolphin", {showLines:true});


/*
This function helps visualize the morph's origin (only for type:"rotational" morphs).
Simply pass in the the two targets (the starting SVG element and ending SVG element)
and it'll morph them, adding a red circle to show the origin. You can drag it around and once
you release it, you'll see the animation updated accordingly. If you drag it when the shape
is in its "end" state, it'll update the end origin. Drag in its "start" state and it'll
update the start origin.

Example:
findMorphOrigin(".start", ".end", {showLines:true});

Optionally pass in a vars object as the 3rd parameter with things like:
{showLines:true, scale:1.5, lineColor:"white", lineOpacity:0.5, lineWidth:1, origin:"40% 20%"}

Draggable is required (you can load it from the CDN at https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.0/utils/Draggable.min.js)
*/
function findMorphOrigin(target1, target2, vars) {
	vars = vars || {};
	TweenLite.killTweensOf(target1, false, {morphSVG:true});
	var _getElement = function(e) {
			return (typeof(e) === "string") ? document.querySelector(e) : e;
		},
		_setDefaults = function(v, defaults) {
			v = v || {};
			for (var p in defaults) {
				if (!(p in v)) {
					v[p] = defaults[p];
				}
			}
			return v;
		},
		_createSVG = function(type, container, attributes) {
			var element = document.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]);
			}
			container.appendChild(element);
			return element;
		},
		editing = "start",
		lines, startOrigin, endOrigin,
		_createLines = function() {
			var rawPath = startElement._gsRawPath,
				i, j, segment, line;
			lines = [];
			for (j = 0; j < rawPath.length; j++) {
				segment = rawPath[j];
				for (i = 0; i < segment.length; i+=6) {
					line = _createSVG("line", startElement.ownerSVGElement, {stroke:v.lineColor, strokeWidth:v.lineWidth});
					line.style.opacity = v.lineOpacity;
					lines.push(line);
				}
				g.parentNode.appendChild(g);
			}
			return lines;
		},
		_update = function(leaveOrigin) {
			var rawPath = startElement._gsRawPath,
				li = 0,
				localToGlobal = globalG.getCTM().inverse().multiply(startElement.getCTM()),
				globalToLocal = localToGlobal.inverse(),
				o, j, i, sl, line, segment, ox, oy, x, y;
			if (rawPath && rawPath.origin) {
				if (leaveOrigin) {
					ox = g._gsTransform.x;
					oy = g._gsTransform.y;
				} else {
					o = rawPath.origin;
					ox = o.x * localToGlobal.a + o.y * localToGlobal.c + localToGlobal.e;
					oy = o.x * localToGlobal.b + o.y * localToGlobal.d + localToGlobal.f;
					TweenLite.set(g, {x:ox, y:oy});
				}
				if (v.showLines) {
					if (!lines) {
						_createLines();
					}
					for (j = 0; j < rawPath.length; j++) {
						segment = rawPath[j];
						sl = segment.length;
						for (i = 0; i < sl; i+=6) {
							line = lines[li++];
							line.setAttribute("x1", ox);
							line.setAttribute("y1", oy);
							line.setAttribute("x2", segment[i] * localToGlobal.a + segment[i+1] * localToGlobal.c + localToGlobal.e);
							line.setAttribute("y2", segment[i] * localToGlobal.b + segment[i+1] * localToGlobal.d + localToGlobal.f);
						}
					}
				}
				if (leaveOrigin) {
					x = ((ox * globalToLocal.a + oy * globalToLocal.c + globalToLocal.e) - rawPath.left) / rawPath.width;
					y = ((ox * globalToLocal.c + oy * globalToLocal.d + globalToLocal.f) - rawPath.top) / rawPath.height;
					if (editing === "start") {
						startOrigin = Math.round(x * 100) + "% " + Math.round(y * 100) + "%";
					} else {
						endOrigin = Math.round(x * 100) + "% " + Math.round(y * 100) + "%";
					}
					label.textContent = startOrigin + (endOrigin ? ", " + endOrigin : "");
				}
			}
		},
		startElement = _getElement(target1),
		v = _setDefaults(vars, {fill:"green", scale:1, origin:"50% 50%", lineColor:"white", lineWidth:0.5, lineOpacity:0.35, duration:2.25, ease:Power1.easeInOut, draggable:true}),
		globalG = _createSVG("g", startElement.ownerSVGElement), //Firefox returns null for ownerSVGElement.getCTM(), so we need a dummy element
		labelG = _createSVG("g", startElement.ownerSVGElement),
		rect = _createSVG("rect", labelG, {width:120, height:17}),
		label = _createSVG("text", labelG, {textAnchor:"middle"}),
		g = _createSVG("g", startElement.ownerSVGElement),
		clickArea = _createSVG("circle", g, {r:20, style:"fill:transparent"}),
		origin = _createSVG("circle", g, {r:4, style:"fill:" + v.fill + ";stroke:" + v.lineColor}),
		tween = TweenMax.to(target1, v.duration, {morphSVG:{shape:target2, type:"rotational", origin:v.origin, smoothTolerance:v.smoothTolerance}, onUpdate:_update, ease:v.ease}),
		bbox = startElement.getBBox(),
		globalToLocal = globalG.getCTM().inverse().multiply(startElement.getCTM()).inverse(),
		localToGlobal = globalG.getCTM().inverse().multiply(startElement.getCTM()),
		tl = new TimelineMax({yoyo:true, repeat:-1, repeatDelay:1.25}),
		rawPath;

	TweenLite.set(rect, {y:-17, x: -60, fill:"black", opacity:0.4});
	TweenLite.set(label, {y:-5, fontSize:10, fill:"white"});
	TweenLite.set([g, labelG], {scale:v.scale, svgOrigin:"0 0"});
	TweenLite.set(labelG, {x:bbox.x + bbox.width / 2 + localToGlobal.e, y:bbox.y + bbox.height + localToGlobal.f});
	tl.add(tween, 0)
		.to(origin, v.duration, {fill:"red", ease:SteppedEase.config(1)}, 0);
	tl.time(0.0001);
	rawPath = startElement._gsRawPath;
	if (!rawPath || !rawPath.origin) {
		throw "Please update to the latest MorphSVGPlugin";
	}
	if (v.origin.indexOf(",") !== -1) {
		endOrigin = v.origin.split(",")[1];
	}
	_update();
	_update(true);
	if (window.Draggable) {
		Draggable.create(g, {
			onPress:function() {
				if (tl.pause().progress() < 0.5) {
					editing = "start";
					tl.progress(0.0001);
				} else {
					editing = "end";
					tl.progress(0.99999);
				}
				MorphSVGPlugin.getTotalSize(startElement._gsRawPath); //re-calculates the top/left/width/height and attaches those to the rawPath.
				TweenLite.set(g, {x:this.x, y:this.y});
				_update(true);
			},
			onDrag:function() {
				_update(true);
			},
			onRelease:function() {
				var time = tl.time(); //globalToLocal = startElement.ownerSVGElement.getCTM().inverse().multiply(startElement.getCTM()).inverse()
				tween.vars.morphSVG.origin = startOrigin + (endOrigin ? "," + endOrigin : "");
				tl.totalTime(0).invalidate().play(time > 0.001 ? time + 1.25 : 0);
			}
		});
	} else {
		console.log("Please load Draggable for findMorphOrigin() to work.")
	}
	return tl;
}
              
            
!
999px

Console