/* all credit to: https://tympanus.net/Development/MorphingBackgroundShapes/index.html ~~ i just got rid of anything that wasn't the lil' bean movin' ~~ */ /* anime.js 2017 Julian Garnier Released under the MIT license */ var $jscomp$this=this; (function(u,r){"function"===typeof define&&define.amd?define([],r):"object"===typeof module&&module.exports?module.exports=r():u.anime=r()})(this,function(){function u(a){if(!g.col(a))try{return document.querySelectorAll(a)}catch(b){}}function r(a){return a.reduce(function(a,c){return a.concat(g.arr(c)?r(c):c)},[])}function v(a){if(g.arr(a))return a;g.str(a)&&(a=u(a)||a);return a instanceof NodeList||a instanceof HTMLCollection?[].slice.call(a):[a]}function E(a,b){return a.some(function(a){return a===b})} function z(a){var b={},c;for(c in a)b[c]=a[c];return b}function F(a,b){var c=z(a),d;for(d in a)c[d]=b.hasOwnProperty(d)?b[d]:a[d];return c}function A(a,b){var c=z(a),d;for(d in b)c[d]=g.und(a[d])?b[d]:a[d];return c}function R(a){a=a.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(a,b,c,h){return b+b+c+c+h+h});var b=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a);a=parseInt(b[1],16);var c=parseInt(b[2],16),b=parseInt(b[3],16);return"rgb("+a+","+c+","+b+")"}function S(a){function b(a,b,c){0> c&&(c+=1);1c?b:c<2/3?a+(b-a)*(2/3-c)*6:a}var c=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(a);a=parseInt(c[1])/360;var d=parseInt(c[2])/100,c=parseInt(c[3])/100;if(0==d)d=c=a=c;else{var e=.5>c?c*(1+d):c+d-c*d,k=2*c-e,d=b(k,e,a+1/3),c=b(k,e,a);a=b(k,e,a-1/3)}return"rgb("+255*d+","+255*c+","+255*a+")"}function w(a){if(a=/([\+\-]?[0-9#\.]+)(%|px|pt|em|rem|in|cm|mm|ex|pc|vw|vh|deg|rad|turn)?/.exec(a))return a[2]}function T(a){if(-1k&&q=m&&(f.began=!0,e("begin")),e("run")):(q<=k&&0!==O&&(d(0),p&&g()),q>=h&&O!==h&&(d(h),p||g()));a>=h&&(f.remaining?(t=n,"alternate"===f.direction&&(f.reversed=!f.reversed)):(f.pause(),P(),Q=b(),f.completed||(f.completed=!0,e("complete"))),l=0);if(f.children)for(a=f.children,h=0;h=b&& 0<=d&&1>=d){var g=new Float32Array(11);if(b!==c||d!==e)for(var h=0;11>h;++h)g[h]=a(.1*h,b,d);return function(h){if(b===c&&d===e)return h;if(0===h)return 0;if(1===h)return 1;for(var k=0,l=1;10!==l&&g[l]<=h;++l)k+=.1;--l;var l=k+(h-g[l])/(g[l+1]-g[l])*.1,n=3*(1-3*d+3*b)*l*l+2*(3*d-6*b)*l+3*b;if(.001<=n){for(k=0;4>k;++k){n=3*(1-3*d+3*b)*l*l+2*(3*d-6*b)*l+3*b;if(0===n)break;var m=a(l,b,d)-h,l=l-m/n}h=l}else if(0===n)h=l;else{var l=k,k=k+.1,f=0;do m=l+(k-l)/2,n=a(m,b,d)-h,0++f);h=m}return a(h,c,e)}}}}(),M=function(){function a(a,b){return 0===a||1===a?a:-Math.pow(2,10*(a-1))*Math.sin(2*(a-1-b/(2*Math.PI)*Math.asin(1))*Math.PI/b)}var b="Quad Cubic Quart Quint Sine Expo Circ Back Elastic".split(" "),c={In:[[.55,.085,.68,.53],[.55,.055,.675,.19],[.895,.03,.685,.22],[.755,.05,.855,.06],[.47,0,.745,.715],[.95,.05,.795,.035],[.6,.04,.98,.335],[.6,-.28,.735,.045],a],Out:[[.25,.46,.45,.94],[.215,.61,.355,1],[.165,.84,.44,1],[.23,1,.32,1],[.39,.575,.565,1],[.19,1,.22,1], [.075,.82,.165,1],[.175,.885,.32,1.275],function(b,c){return 1-a(1-b,c)}],InOut:[[.455,.03,.515,.955],[.645,.045,.355,1],[.77,0,.175,1],[.86,0,.07,1],[.445,.05,.55,.95],[1,0,0,1],[.785,.135,.15,.86],[.68,-.55,.265,1.55],function(b,c){return.5>b?a(2*b,c)/2:1-a(-2*b+2,c)/2}]},d={linear:x(.25,.25,.75,.75)},e={},k;for(k in c)e.type=k,c[e.type].forEach(function(a){return function(c,e){d["ease"+a.type+b[e]]=g.fnc(c)?c:x.apply($jscomp$this,c)}}(e)),e={type:e.type};return d}(),ha={css:function(a,b,c){return a.style[b]= c},attribute:function(a,b,c){return a.setAttribute(b,c)},object:function(a,b,c){return a[b]=c},transform:function(a,b,c,d,e){d[e]||(d[e]=[]);d[e].push(b+"("+c+")")}},p=[],y=0,ia=function(){function a(){y=requestAnimationFrame(b)}function b(b){var c=p.length;if(c){for(var e=0;ed&&(b.duration=a.duration);b.children.push(a)});return b};return b};m.random=function(a,b){return Math.floor(Math.random()*(b-a+1))+a};return m}); /** * demo1.js * http://www.codrops.com * * Licensed under the MIT license. * http://www.opensource.org/licenses/mit-license.php * * Copyright 2017, Codrops * http://www.codrops.com */ { // Helper vars and functions. const extend = function(a, b) { for( let key in b ) { if( b.hasOwnProperty( key ) ) { a[key] = b[key]; } } return a; }; // from http://www.quirksmode.org/js/events_properties.html#position const getMousePos = function(ev) { let posx = 0; let posy = 0; if (!ev) ev = window.event; if (ev.pageX || ev.pageY) { posx = ev.pageX; posy = ev.pageY; } else if (ev.clientX || ev.clientY) { posx = ev.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; posy = ev.clientY + document.body.scrollTop + document.documentElement.scrollTop; } return { x : posx, y : posy }; }; const TiltObj = function(el, options) { this.el = el; this.options = extend({}, this.options); extend(this.options, options); this.DOM = {}; this.DOM.img = this.el.querySelector('.content__img'); this.DOM.title = this.el.querySelector('.content__title'); this._initEvents(); }; TiltObj.prototype.options = { movement: { img : { translation : {x: -10, y: -10} }, title : { translation : {x: 25, y: 25} }, } }; TiltObj.prototype._initEvents = function() { this.mouseenterFn = (ev) => { anime.remove(this.DOM.img); anime.remove(this.DOM.title); }; this.mousemoveFn = (ev) => { requestAnimationFrame(() => this._layout(ev)); }; this.mouseleaveFn = (ev) => { requestAnimationFrame(() => { anime({ targets: [this.DOM.img, this.DOM.title], duration: 1500, easing: 'easeOutElastic', elasticity: 400, translateX: 0, translateY: 0 }); }); }; this.el.addEventListener('mousemove', this.mousemoveFn); this.el.addEventListener('mouseleave', this.mouseleaveFn); this.el.addEventListener('mouseenter', this.mouseenterFn); }; TiltObj.prototype._layout = function(ev) { // Mouse position relative to the document. const mousepos = getMousePos(ev); // Document scrolls. const docScrolls = {left : document.body.scrollLeft + document.documentElement.scrollLeft, top : document.body.scrollTop + document.documentElement.scrollTop}; const bounds = this.el.getBoundingClientRect(); // Mouse position relative to the main element (this.DOM.el). const relmousepos = { x : mousepos.x - bounds.left - docScrolls.left, y : mousepos.y - bounds.top - docScrolls.top }; // Movement settings for the animatable elements. const t = { img: this.options.movement.img.translation, title: this.options.movement.title.translation, }; const transforms = { img : { x: (-1*t.img.x - t.img.x)/bounds.width*relmousepos.x + t.img.x, y: (-1*t.img.y - t.img.y)/bounds.height*relmousepos.y + t.img.y }, title : { x: (-1*t.title.x - t.title.x)/bounds.width*relmousepos.x + t.title.x, y: (-1*t.title.y - t.title.y)/bounds.height*relmousepos.y + t.title.y } }; this.DOM.img.style.WebkitTransform = this.DOM.img.style.transform = 'translateX(' + transforms.img.x + 'px) translateY(' + transforms.img.y + 'px)'; this.DOM.title.style.WebkitTransform = this.DOM.title.style.transform = 'translateX(' + transforms.title.x + 'px) translateY(' + transforms.title.y + 'px)'; }; const DOM = {}; DOM.svg = document.querySelector('.morph'); DOM.shapeEl = DOM.svg.querySelector('path'); DOM.contentElems = Array.from(document.querySelectorAll('.content-wrap')); DOM.contentLinks = Array.from(document.querySelectorAll('.content__link')); DOM.footer = document.querySelector('.content--related'); const contentElemsTotal = DOM.contentElems.length; const shapes = [ { path: 'M 262.9,252.2 C 210.1,338.2 212.6,487.6 288.8,553.9 372.2,626.5 511.2,517.8 620.3,536.3 750.6,558.4 860.3,723 987.3,686.5 1089,657.3 1168,534.7 1173,429.2 1178,313.7 1096,189.1 995.1,130.7 852.1,47.07 658.8,78.95 498.1,119.2 410.7,141.1 322.6,154.8 262.9,252.2 Z', pathAlt: 'M 262.9,252.2 C 210.1,338.2 273.3,400.5 298.5,520 323.7,639.6 511.2,537.2 620.3,555.7 750.6,577.8 872.2,707.4 987.3,686.5 1102,665.6 1218,547.8 1173,429.2 1128,310.6 1096,189.1 995.1,130.7 852.1,47.07 658.8,78.95 498.1,119.2 410.7,141.1 322.6,154.8 262.9,252.2 Z', scaleX: 1.2, scaleY: 1, rotate: 0, tx: -30, ty: -100, animation: { path: { duration: 3000, easing: 'easeOutElastic', elasticity: 600 }, svg: { duration: 2000, easing: 'easeOutElastic' } } }, { path: 'M 415.6,206.3 C 407.4,286.6 438.1,373.6 496.2,454.8 554.3,536.1 497,597.2 579.7,685.7 662.4,774.1 834.3,731.7 898.5,653.4 962.3,575 967.1,486 937.7,370 909.3,253.9 937.7,201.5 833.4,105.4 729.3,9.338 602.2,13.73 530.6,41.91 459,70.08 423.9,126.1 415.6,206.3 Z', pathAlt: 'M 415.6,206.3 C 407.4,286.6 415.5,381.7 473.6,462.9 531.7,544.2 482.5,637.6 579.7,685.7 676.9,733.8 826.2,710.7 890.4,632.4 954.2,554 926.8,487.6 937.7,370 948.6,252.4 937.7,201.5 833.4,105.4 729.3,9.338 602.2,13.73 530.6,41.91 459,70.08 423.9,126.1 415.6,206.3 Z', scaleX: .4, scaleY: 1.4, rotate: 0, tx: 0, ty: -100, animation: { path: { duration: 2000, easing: 'easeOutElastic', elasticity: 600 }, svg: { duration: 2000, easing: 'easeOutElastic' } } }, { path: 'M 383.8,163.4 C 335.8,352.3 591.6,317.1 608.7,420.8 625.8,524.5 580.5,626 647.3,688 714,750 837.1,760.5 940.9,661.5 1044,562.3 1041,455.8 975.8,393.6 909.8,331.5 854.2,365.4 784.4,328.1 714.6,290.8 771.9,245.2 733.1,132.4 694.2,19.52 431.9,-25.48 383.8,163.4 Z', pathAlt: 'M 383.8,163.4 C 345.5,324.9 591.6,317.1 608.7,420.8 625.8,524.5 595.1,597 647.3,688 699.5,779 837.1,760.5 940.9,661.5 1044,562.3 1068,444.4 975.8,393.6 884,342.8 854.2,365.4 784.4,328.1 714.6,290.8 820.3,237.2 733.1,132.4 645.9,27.62 422.1,1.919 383.8,163.4 Z', scaleX: .7, scaleY: 1.1, rotate: -20, tx: 200, ty: 200, animation: { path: { duration: 3000, easing: 'easeOutElastic', elasticity: 600 }, svg: { duration: 2500, easing: 'easeOutElastic' } } }, { path: 'M 262.9,252.2 C 210.1,338.2 212.6,487.6 288.8,553.9 372.2,626.5 511.2,517.8 620.3,536.3 750.6,558.4 860.3,723 987.3,686.5 1089,657.3 1168,534.7 1173,429.2 1178,313.7 1096,189.1 995.1,130.7 852.1,47.07 658.8,78.95 498.1,119.2 410.7,141.1 322.6,154.8 262.9,252.2 Z', pathAlt: 'M 262.9,252.2 C 210.1,338.2 273.3,400.5 298.5,520 323.7,639.6 511.2,537.2 620.3,555.7 750.6,577.8 872.2,707.4 987.3,686.5 1102,665.6 1218,547.8 1173,429.2 1128,310.6 1096,189.1 995.1,130.7 852.1,47.07 658.8,78.95 498.1,119.2 410.7,141.1 322.6,154.8 262.9,252.2 Z', scaleX: 1.5, scaleY: 1, rotate: -20, tx: 0, ty: -50, animation: { path: { duration: 3000, easing: 'easeOutQuad', elasticity: 600 }, svg: { duration: 3000, easing: 'easeOutElastic' } } }, { path: 'M 247.6,239.6 C 174.3,404.5 245.5,601.9 358.5,624.3 471.5,646.6 569.1,611.6 659.7,655.7 750.4,699.7 1068,687.6 1153,534.4 1237,381.1 1114,328.4 1127,227.4 1140,126.3 1016,51.08 924.6,116.8 833.8,182.5 928.4,393.8 706.8,283.5 485.2,173.1 320.8,74.68 247.6,239.6 Z', pathAlt: 'M 247.6,239.6 C 174.3,404.5 271.3,550.3 358.5,624.3 445.7,698.3 569.1,611.6 659.7,655.7 750.4,699.7 1145,699 1153,534.4 1161,369.8 1114,328.4 1127,227.4 1140,126.3 1016,51.08 924.6,116.8 833.8,182.5 894.5,431 706.8,283.5 519.1,136 320.8,74.68 247.6,239.6 Z', scaleX: 1.8, scaleY: 1.5, rotate: 0, tx: 250, ty: 50, animation: { path: { duration: 3000, easing: 'easeOutElastic', elasticity: 600 }, svg: { duration: 2000, easing: 'easeOutExpo' } } }, // footer shape: { path: 'M 262.9,252.2 C 210.1,338.2 212.6,487.6 288.8,553.9 372.2,626.5 511.2,517.8 620.3,536.3 750.6,558.4 860.3,723 987.3,686.5 1089,657.3 1168,534.7 1173,429.2 1178,313.7 1096,189.1 995.1,130.7 852.1,47.07 658.8,78.95 498.1,119.2 410.7,141.1 322.6,154.8 262.9,252.2 Z', pathAlt: 'M 262.9,252.2 C 210.1,338.2 273.3,400.5 298.5,520 323.7,639.6 511.2,537.2 620.3,555.7 750.6,577.8 872.2,707.4 987.3,686.5 1102,665.6 1218,547.8 1173,429.2 1128,310.6 1096,189.1 995.1,130.7 852.1,47.07 658.8,78.95 498.1,119.2 410.7,141.1 322.6,154.8 262.9,252.2 Z', scaleX: 2.5, scaleY: 2, rotate: 0, tx: 0, ty: -50, animation: { path: { duration: 3000, easing: 'easeOutQuad', elasticity: 600 }, svg: { duration: 3000, easing: 'easeOutElastic' } } } ]; let step; const initShapeLoop = function(pos) { pos = pos || 0; anime.remove(DOM.shapeEl); anime({ targets: DOM.shapeEl, easing: 'linear', d: [{value: shapes[pos].pathAlt, duration:3500}, {value: shapes[pos].path, duration:3500}], loop: true, direction: 'alternate' }); }; const initShapeEl = function() { anime.remove(DOM.svg); anime({ targets: DOM.svg, duration: 1, easing: 'linear', scaleX: shapes[0].scaleX, scaleY: shapes[0].scaleY, translateX: shapes[0].tx+'px', translateY: shapes[0].ty+'px', rotate: shapes[0].rotate+'deg' }); initShapeLoop(); }; const createScrollWatchers = function() { DOM.contentElems.forEach((el,pos) => { const scrollElemToWatch = pos ? DOM.contentElems[pos] : DOM.footer; pos = pos ? pos : contentElemsTotal; const watcher = scrollMonitor.create(scrollElemToWatch,-300); watcher.enterViewport(function() { step = pos; anime.remove(DOM.shapeEl); anime({ targets: DOM.shapeEl, duration: shapes[pos].animation.path.duration, easing: shapes[pos].animation.path.easing, elasticity: shapes[pos].animation.path.elasticity || 0, d: shapes[pos].path, complete: function() { initShapeLoop(pos); } }); anime.remove(DOM.svg); anime({ targets: DOM.svg, duration: shapes[pos].animation.svg.duration, easing: shapes[pos].animation.svg.easing, elasticity: shapes[pos].animation.svg.elasticity || 0, scaleX: shapes[pos].scaleX, scaleY: shapes[pos].scaleY, translateX: shapes[pos].tx+'px', translateY: shapes[pos].ty+'px', rotate: shapes[pos].rotate+'deg' }); }); watcher.exitViewport(function() { const idx = !watcher.isAboveViewport ? pos-1 : pos+1; if( idx <= contentElemsTotal && step !== idx ) { step = idx; anime.remove(DOM.shapeEl); anime({ targets: DOM.shapeEl, duration: shapes[idx].animation.path.duration, easing: shapes[idx].animation.path.easing, elasticity: shapes[idx].animation.path.elasticity || 0, d: shapes[idx].path, complete: function() { initShapeLoop(idx); } }); anime.remove(DOM.svg); anime({ targets: DOM.svg, duration: shapes[idx].animation.svg.duration, easing: shapes[idx].animation.svg.easing, elasticity: shapes[idx].animation.svg.elasticity || 0, scaleX: shapes[idx].scaleX, scaleY: shapes[idx].scaleY, translateX: shapes[idx].tx+'px', translateY: shapes[idx].ty+'px', rotate: shapes[idx].rotate+'deg' }); } }); }); }; initShapeEl(); };