Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              svg(viewBox='0 0 2000 2000')
	mask#m
		rect(width='100%' height='100%' fill='#fff')
		ellipse(cx=1000 cy=730 rx=250 ry=310)
	path#s(ini=`M855 1425c-35-49-100-70-170-70-98 0-328 95-328 295l0 0c0 39 19 192 200 192c250 0 340-205 340-305v-1070c125 90 425 230 425 470c0 190-110 290-210 400l23 25c95-75 241-265 241-450c0-425-395-485-485-805h-35z` 
			 fin=`M1265 1085c0 435-150 545-290 545-145 0-190-105-215-180l-320 50c65 265 225 395 565 395c397 0 597-380 597-835v-130c0-390-135-775-620-775-390 0-570 265-570 575l0 0c0 355 200 555 500 555c135 0 295-48 355-198h0z`)
            
          
!
            
              body {
	display: flex;
	margin: 0;
	height: 100vh;
	background: url(http://www.blirk.net/wallpapers/1920x1080/music-wallpaper-33.jpg) 100% 50%/ cover #999;
	background-blend-mode: screen
}

svg { flex: 1 }

[id='s'] { mask: url(#m) }
            
          
!
            
              const DATA = {
				p: {
					_el: document.querySelector('path'),
					att: {}
				},
				e: {
					_el: document.querySelector('ellipse'),
					att: {}
				}
			}, 
			RE = /\s+|[a-z]/g,
			NF = 40 /* total number of frames for transition */, 
      TFN = { /* timing functions */
        'ease-in-out': function(k) {
          return .5*(Math.sin((k - .5)*Math.PI) + 1)
        },
        'bounce-ini-fin': function(k, s = -.675*Math.PI, e = -s) {
          return (Math.sin(k*(e - s) + s) - Math.sin(s))/(Math.sin(e) - Math.sin(s))
        }
      };

let dir = -1, rID = null, cf = 0, m;

function extractStr(el, attr = 'ini') {
	const SEP_RE = /(\d)\-/g;
	
	return el.getAttribute(attr).slice(1, -1)
					 .replace(SEP_RE, '$1 -');
};

function extractPts(str) {
	return str.split(RE).map(c => +c)
};

function extractSep(str) {
	return str.match(RE)
};

function range(ini, fin) {
	return (typeof ini == 'number') ? 
					fin - ini : 
					ini.map((c, i) => range(ini[i], fin[i]))
};

function int(ini, rng, tfn, k, cnt) {
	return (typeof ini == 'number') ? 
					+(ini + cnt*(m + dir*tfn(m + dir*k))*rng).toFixed(2) : 
					ini.map((c, i) => int(ini[i], rng[i], tfn, k, cnt))
};

function stopAni() {
  cancelAnimationFrame(rID);
  rID = null;  
};

function update() {
	cf += dir;
	
  let k = cf/NF;
	
	for(let e in DATA) {
		for(let p in DATA[e].att) {
			let o = DATA[e].att[p];
			
			DATA[e]._el.setAttribute(...[
				p, 
				o.afn(int(o.ini, o.rng, TFN[o.tfn], k, o.cnt ? dir : 1), o.sep)
			]);
		}
	}
  
  if(!(cf%NF)) {
    stopAni();
    return
  }
  
  rID = requestAnimationFrame(update)
};

(function init() {
	const INI_STR = extractStr(DATA.p._el);
	
	DATA.p.att.d = {
		sep: extractSep(INI_STR),
		ini: extractPts(INI_STR), 
		fin: extractPts(extractStr(DATA.p._el, 'fin')),
		afn: function(pts, sep) {
			return pts.reduce((a, c, i) => a + c + (sep[i] || 'z'), 'M')
		},
		tfn: 'bounce-ini-fin'
	};
	
	['rx', 'ry', 'opacity'].forEach(c => {
		DATA.e.att[c] = {
			ini: 0, 
			fin: DATA.e._el.getAttribute(c) || 1,
			afn: i => i,
			tfn: 'ease-in-out'
		}
	});
	
	for(let e in DATA) {
		for(let p in DATA[e].att) {
			let o = DATA[e].att[p];
			
			o.rng = range(o.ini, o.fin);
			DATA[e]._el.setAttribute(p, o.afn(o.ini, o.sep))
		}
	}
	
	addEventListener('click', e => {
		if(rID) stopAni();
		dir *= -1;
		m = .5*(1 - dir);
		update();
	}, false);
})();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console