123

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.

            
              <div>
<a class="bg-granim-rainbow">
<img src="http://photoshopvip.net/wp-content/uploads/2016/10/logo_sample3.png">
</a>
</div>
            
          
!
            
              body{ 
  background-color: #fefefe;
}
div{
  text-align: center;
  padding: 22px 16px 0px;
}
a{
	overflow: hidden;
	display: inline-block;
	font-size: 0;
}
img{
  max-width: 223px;
  width 100%;
}
            
          
!
            
              /* 
Granim v1.0.6 - https://sarcadass.github.io/granim.js 

The MIT License (MIT)
Copyright (c) 2016 Benjamin Blonde
Released under the MIT license
https://github.com/sarcadass/granim.js/blob/master/LICENSE

Modified by ya90net
*/
!function t(e,s,i){function n(a,r){if(!s[a]){if(!e[a]){var h="function"==typeof require&&require;if(!r&&h)return h(a,!0);if(o)return o(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var l=s[a]={exports:{}};e[a][0].call(l.exports,function(t){var s=e[a][1][t];return n(s?s:t)},l,l.exports,t,e,s,i)}return s[a].exports}for(var o="function"==typeof require&&require,a=0;a<i.length;a++)n(i[a]);return n}({1:[function(t,e,s){"use strict";function i(t){this.getElement(t.element),this.x1=0,this.y1=0,this.name=t.name||!1,this.elToSetClassOn=t.elToSetClassOn||"body",this.direction=t.direction||"diagonal",this.isPausedWhenNotInView=t.isPausedWhenNotInView||!1,this.opacity=t.opacity,this.states=t.states,this.stateTransitionSpeed=t.stateTransitionSpeed||1e3,this.previousTimeStamp=null,this.progress=0,this.isPaused=!1,this.isCleared=!1,this.isPausedBecauseNotInView=!1,this.iscurrentColorsSet=!1,this.context=this.canvas.getContext("2d"),this.channels={},this.channelsIndex=0,this.activeState=t.defaultStateName||"default-state",this.isChangingState=!1,this.activeColors=[],this.activeColorDiff=[],this.activetransitionSpeed=null,this.currentColors=[],this.eventPolyfill(),this.events={start:new CustomEvent("granim:start"),end:new CustomEvent("granim:end"),gradientChange:function(t){return new CustomEvent("granim:gradientChange",{detail:{isLooping:t.isLooping,colorsFrom:t.colorsFrom,colorsTo:t.colorsTo,activeState:t.activeState},bubbles:!1,cancelable:!1})}},this.callbacks={onStart:"function"==typeof t.onStart&&t.onStart,onGradientChange:"function"==typeof t.onGradientChange&&t.onGradientChange,onEnd:"function"==typeof t.onEnd&&t.onEnd},this.getDimensions(),this.canvas.setAttribute("width",this.x1),this.canvas.setAttribute("height",this.y1),this.setColors(),this.refreshColors(),window.addEventListener("resize",this.onResize.bind(this)),this.isPausedWhenNotInView?this.pauseWhenNotInView():this.animation=requestAnimationFrame(this.animateColors.bind(this)),this.callbacks.onStart&&this.callbacks.onStart(),this.canvas.dispatchEvent(this.events.start)}i.prototype.setColors=t("./setColors.js"),i.prototype.eventPolyfill=t("./eventPolyfill.js"),i.prototype.colorDiff=t("./colorDiff.js"),i.prototype.hexToRgb=t("./hexToRgb.js"),i.prototype.setDirection=t("./setDirection.js"),i.prototype.makeGradient=t("./makeGradient.js"),i.prototype.getDimensions=t("./getDimensions.js"),i.prototype.getElement=t("./getElement.js"),i.prototype.animateColors=t("./animateColors.js"),i.prototype.getLightness=t("./getLightness.js"),i.prototype.refreshColors=t("./refreshColors.js"),i.prototype.changeState=t("./changeState.js"),i.prototype.pause=t("./pause.js"),i.prototype.play=t("./play.js"),i.prototype.clear=t("./clear.js"),i.prototype.getCurrentColors=t("./getCurrentColors.js"),i.prototype.pauseWhenNotInView=t("./pauseWhenNotInView.js"),i.prototype.onResize=t("./onResize.js"),e.exports=i},{"./animateColors.js":2,"./changeState.js":3,"./clear.js":4,"./colorDiff.js":5,"./eventPolyfill.js":6,"./getCurrentColors.js":7,"./getDimensions.js":8,"./getElement.js":9,"./getLightness.js":10,"./hexToRgb.js":11,"./makeGradient.js":12,"./onResize.js":13,"./pause.js":14,"./pauseWhenNotInView.js":15,"./play.js":16,"./refreshColors.js":17,"./setColors.js":18,"./setDirection.js":19}],2:[function(t,e,s){"use strict";e.exports=function(t){var e,s,i,n=t-this.previousTimeStamp>100,o=void 0===this.states[this.activeState].loop||this.states[this.activeState].loop;(null===this.previousTimeStamp||n)&&(this.previousTimeStamp=t),this.progress=this.progress+(t-this.previousTimeStamp),e=(this.progress/this.activetransitionSpeed*100).toFixed(2),this.previousTimeStamp=t,this.refreshColors(e),e<100?this.animation=requestAnimationFrame(this.animateColors.bind(this)):this.channelsIndex<this.states[this.activeState].gradients.length-2||o?(this.isChangingState&&(this.activetransitionSpeed=this.states[this.activeState].transitionSpeed||5e3),this.previousTimeStamp=null,this.progress=0,this.channelsIndex++,s=!1,this.channelsIndex===this.states[this.activeState].gradients.length-1?s=!0:this.channelsIndex===this.states[this.activeState].gradients.length&&(this.channelsIndex=0),i=void 0===this.states[this.activeState].gradients[this.channelsIndex+1]?this.states[this.activeState].gradients[0]:this.states[this.activeState].gradients[this.channelsIndex+1],this.setColors(),this.animation=requestAnimationFrame(this.animateColors.bind(this)),this.callbacks.onGradientChange&&this.callbacks.onGradientChange({isLooping:s,colorsFrom:this.states[this.activeState].gradients[this.channelsIndex],colorsTo:i,activeState:this.activeState}),this.canvas.dispatchEvent(this.events.gradientChange({isLooping:s,colorsFrom:this.states[this.activeState].gradients[this.channelsIndex],colorsTo:i,activeState:this.activeState}))):(cancelAnimationFrame(this.animation),this.callbacks.onEnd&&this.callbacks.onEnd(),this.canvas.dispatchEvent(new CustomEvent("granim:end")))}},{}],3:[function(t,e,s){"use strict";e.exports=function(t){var e,s,i=this;this.activeState!==t&&(this.isPaused||(this.isPaused=!0,this.pause()),this.channelsIndex=-1,this.activetransitionSpeed=this.stateTransitionSpeed,this.activeColorDiff=[],this.activeColors=this.getCurrentColors(),this.progress=0,this.previousTimeStamp=null,this.isChangingState=!0,this.states[t].gradients[0].forEach(function(n,o,a){e=i.hexToRgb(i.states[t].gradients[0][o]),s=i.colorDiff(i.activeColors[o],e),i.activeColorDiff.push(s)}),this.activeState=t,this.play())}},{}],4:[function(t,e,s){"use strict";e.exports=function(){this.isPaused?this.isPaused=!1:cancelAnimationFrame(this.animation),this.isCleared=!0,this.context.clearRect(0,0,this.x1,this.y1)}},{}],5:[function(t,e,s){"use strict";e.exports=function(t,e){var s,i=[];for(s=0;s<3;s++)i.push(e[s]-t[s]);return i}},{}],6:[function(t,e,s){"use strict";e.exports=function(){function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var s=document.createEvent("CustomEvent");return s.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),s}"function"!=typeof window.CustomEvent&&(t.prototype=window.Event.prototype,window.CustomEvent=t)}},{}],7:[function(t,e,s){"use strict";e.exports=function(){var t,e=[];return this.currentColors.forEach(function(s,i,n){for(e.push([]),t=0;t<3;t++)e[i].push(s[t])}),e}},{}],8:[function(t,e,s){"use strict";e.exports=function(){this.x1=this.canvas.offsetWidth,this.y1=this.canvas.offsetHeight}},{}],9:[function(t,e,s){"use strict";e.exports=function(t){if(t instanceof HTMLCanvasElement)this.canvas=t;else{if("string"!=typeof t)throw new Error("The element you used is neither a String, nor a HTMLCanvasElement");this.canvas=document.querySelector(t)}if(!this.canvas)throw new Error("`"+t+"` could not be found in the DOM")}},{}],10:[function(t,e,s){"use strict";e.exports=function(){var t,e=this.getCurrentColors(),s=[],i=null;return e.forEach(function(t,e,i){s.push(Math.max(t[0],t[1],t[2]))}),s.forEach(function(e,n,o){i=null===i?e:i+e,n===s.length-1&&(t=Math.round(i/(n+1)))}),t>=128?"light":"dark"}},{}],11:[function(t,e,s){"use strict";e.exports=function(t){var e=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;t=t.replace(e,function(t,e,s,i){return e+e+s+s+i+i});var s=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return s?[parseInt(s[1],16),parseInt(s[2],16),parseInt(s[3],16)]:null}},{}],12:[function(t,e,s){"use strict";e.exports=function(){var t,e,s=this.setDirection(),i=document.querySelector(this.elToSetClassOn).classList;for(this.context.clearRect(0,0,this.x1,this.y1),t=0;t<this.currentColors.length;t++)e=t?(1/(this.currentColors.length-1)*t).toFixed(2):0,s.addColorStop(e,"rgba("+this.currentColors[t][0]+", "+this.currentColors[t][1]+", "+this.currentColors[t][2]+", "+this.opacity[t]+")");this.name&&("light"===this.getLightness()?(i.remove(this.name+"-dark"),i.add(this.name+"-light")):(i.remove(this.name+"-light"),i.add(this.name+"-dark"))),this.context.fillStyle=s,this.context.fillRect(0,0,this.x1,this.y1)}},{}],13:[function(t,e,s){"use strict";e.exports=function(){this.getDimensions(),this.canvas.setAttribute("width",this.x1),this.canvas.setAttribute("height",this.y1),this.refreshColors()}},{}],14:[function(t,e,s){"use strict";e.exports=function(t){var e="isPausedBecauseNotInView"===t;this.isCleared||(e||(this.isPaused=!0),cancelAnimationFrame(this.animation))}},{}],15:[function(t,e,s){"use strict";e.exports=function(){function t(t){e&&clearTimeout(e),e=setTimeout(function(){var e=s.canvas.getBoundingClientRect(),i=e.bottom<0||e.right<0||e.left>window.innerWidth||e.top>window.innerHeight;i?s.isPaused||s.isPausedBecauseNotInView||(s.isPausedBecauseNotInView=!0,s.pause("isPausedBecauseNotInView")):s.isPaused&&t!==!0||(s.isPausedBecauseNotInView=!1,s.play("isPausedBecauseNotInView"))},300)}var e,s=this;window.addEventListener("scroll",t),t(!0)}},{}],16:[function(t,e,s){"use strict";e.exports=function(t){var e="isPausedBecauseNotInView"===t;e||(this.isPaused=!1),this.isCleared=!1,this.animation=requestAnimationFrame(this.animateColors.bind(this))}},{}],17:[function(t,e,s){"use strict";e.exports=function(t){var e,s,i=this;this.activeColors.forEach(function(n,o,a){for(s=0;s<3;s++)e=i.activeColors[o][s]+Math.ceil(i.activeColorDiff[o][s]/100*t),e<=255&&e>=0&&(i.currentColors[o][s]=e)}),this.makeGradient()}},{}],18:[function(t,e,s){"use strict";e.exports=function(){var t,e,s=this;return this.channels[this.activeState]||(this.channels[this.activeState]=[]),void 0!==this.channels[this.activeState][this.channelsIndex]?(this.activeColors=this.channels[this.activeState][this.channelsIndex].colors,void(this.activeColorDiff=this.channels[this.activeState][this.channelsIndex].colorsDiff)):(this.channels[this.activeState].push([{}]),this.channels[this.activeState][this.channelsIndex].colors=[],this.channels[this.activeState][this.channelsIndex].colorsDiff=[],this.activeColors=[],this.activeColorDiff=[],this.states[this.activeState].gradients[this.channelsIndex].forEach(function(i,n,o){var a=s.hexToRgb(i),r=s.channels[s.activeState];r[s.channelsIndex].colors.push(a),s.activeColors.push(a),s.iscurrentColorsSet||s.currentColors.push(s.hexToRgb(i)),s.channelsIndex===s.states[s.activeState].gradients.length-1?t=s.colorDiff(r[s.channelsIndex].colors[n],r[0].colors[n]):(e=s.hexToRgb(s.states[s.activeState].gradients[s.channelsIndex+1][n]),t=s.colorDiff(r[s.channelsIndex].colors[n],e)),r[s.channelsIndex].colorsDiff.push(t),s.activeColorDiff.push(t)}),this.activetransitionSpeed=this.states[this.activeState].transitionSpeed||5e3,void(this.iscurrentColorsSet=!0))}},{}],19:[function(t,e,s){"use strict";e.exports=function(){var t=this.context;switch(this.direction){default:case"diagonal":return t.createLinearGradient(0,0,this.x1,this.y1);case"left-right":return t.createLinearGradient(0,0,this.x1,0);case"top-bottom":return t.createLinearGradient(this.x1/2,0,this.x1/2,this.y1);case"radial":return t.createRadialGradient(this.x1/2,this.y1/2,this.x1/2,this.x1/2,this.y1/2,0)}}},{}],20:[function(t,e,s){window.Granim=t("./lib/Granim.js")},{"./lib/Granim.js":1}]},{},[20]);
/* Added below by ya90net  */
function hasClass_js(d,b){var c=" "+b+" ",a=d.length;if((" "+d.className+" ").replace(/[\t\r\n\f]/g," ").indexOf(c)>=0){return true}return false}document.addEventListener("DOMContentLoaded",function(){var c=document.querySelectorAll(classes);for(var b=c.length;b--;){var d="granim_canvas"+b;var e="";c[b].setAttribute("style","position:relative;z-index:0;");var a=document.createElement("canvas");a.setAttribute("class",d);a.setAttribute("style","width:100%;height:100%;position:absolute;top:0;left:0;z-index:-1;");c[b].insertBefore(a,c[b].firstChild);if(hasClass_js(c[b],"bg-granim-yellow")||hasClass_js(c[b],"bg-granim-yellow-rad")){gradation=yellow;e=hasClass_js(c[b],"bg-granim-yellow-rad")?"radial":""}else{if(hasClass_js(c[b],"bg-granim-blue")||hasClass_js(c[b],"bg-granim-blue-rad")){gradation=blue;e=hasClass_js(c[b],"bg-granim-blue-rad")?"radial":""}else{if(hasClass_js(c[b],"bg-granim-green")||hasClass_js(c[b],"bg-granim-green-rad")){gradation=green;e=hasClass_js(c[b],"bg-granim-green-rad")?"radial":""}else{if(hasClass_js(c[b],"bg-granim-red")||hasClass_js(c[b],"bg-granim-red-rad")){gradation=red;e=hasClass_js(c[b],"bg-granim-red-rad")?"radial":""}else{if(hasClass_js(c[b],"bg-granim-purple")||hasClass_js(c[b],"bg-granim-purple-rad")){gradation=purple;e=hasClass_js(c[b],"bg-granim-purple-rad")?"radial":""}else{if(hasClass_js(c[b],"bg-granim-purple2")||hasClass_js(c[b],"bg-granim-purple2-rad")){gradation=purple2;e=hasClass_js(c[b],"bg-granim-purple2-rad")?"radial":""}else{if(hasClass_js(c[b],"bg-granim-rainbow")||hasClass_js(c[b],"bg-granim-rainbow-rad")){gradation=rainbow;e=hasClass_js(c[b],"bg-granim-rainbow-rad")?"radial":""}else{if(hasClass_js(c[b],"bg-granim-yellow2")||hasClass_js(c[b],"bg-granim-yellow2-rad")){gradation=yellow2;e=hasClass_js(c[b],"bg-granim-yellow2-rad")?"radial":""}else{if(hasClass_js(c[b],"bg-granim-blue2")||hasClass_js(c[b],"bg-granim-blue2-rad")){gradation=blue2;e=hasClass_js(c[b],"bg-granim-blue2-rad")?"radial":""}else{if(hasClass_js(c[b],"bg-granim-green2")||hasClass_js(c[b],"bg-granim-green2-rad")){gradation=green2;e=hasClass_js(c[b],"bg-granim-green2-rad")?"radial":""}else{if(hasClass_js(c[b],"bg-granim-red2")||hasClass_js(c[b],"bg-granim-red2-rad")){gradation=red2;e=hasClass_js(c[b],"bg-granim-red2-rad")?"radial":""}else{if(hasClass_js(c[b],"bg-granim-mono")||hasClass_js(c[b],"bg-granim-mono-rad")){gradation=mono;e=hasClass_js(c[b],"bg-granim-mono-rad")?"radial":""}else{if(hasClass_js(c[b],"bg-granim-3d")||hasClass_js(c[b],"bg-granim-3d-rad")){gradation=g3d;e=hasClass_js(c[b],"bg-granim-3d-rad")?"radial":""}else{if(hasClass_js(c[b],"bg-granim-pink")||hasClass_js(c[b],"bg-granim-pink-rad")){gradation=hasClass_js(c[b],"bg-granim-pink-rad")?pinkrad:pink;e=hasClass_js(c[b],"bg-granim-pink-rad")?"radial":""}else{if(hasClass_js(c[b],"bg-granim-pink2")||hasClass_js(c[b],"bg-granim-pink2-rad")){gradation=pink2;e=hasClass_js(c[b],"bg-granim-pink2-rad")?"radial":""}}}}}}}}}}}}}}}e=e==""?"diagonal":e;new Granim({element:"."+d,name:"granim",opacity:[1,1],direction:e,states:{"default-state":{gradients:gradation,transitionSpeed:3000}}})}},false);var classes=".bg-granim-yellow,.bg-granim-blue,.bg-granim-green,.bg-granim-red,.bg-granim-pink,.bg-granim-pink2,.bg-granim-purple,.bg-granim-rainbow,.bg-granim-yellow2,.bg-granim-blue2,.bg-granim-green2,.bg-granim-red2,.bg-granim-mono,.bg-granim-3d,.bg-granim-purple2";classes+=",.bg-granim-yellow-rad,.bg-granim-blue-rad,.bg-granim-green-rad,.bg-granim-red-rad,.bg-granim-pink-rad,.bg-granim-pink2-rad,.bg-granim-purple-rad,.bg-granim-rainbow-rad,.bg-granim-yellow2-rad,.bg-granim-blue2-rad,.bg-granim-green2-rad,.bg-granim-red2-rad,.bg-granim-mono-rad,.bg-granim-3d-rad,.bg-granim-purple2-rad";var yellow=[["#FFC107","#ffffff"],["#ffeba9","#FFEB3B"],["#FFC107","#ffffff"],["#FFC107","#FFD54F"]];var yellow2=[["#FFCA28","#FFEB3B"],["#ffb347","#ffcc33"],["#FFEB3B","#FFCA28"],["#ffcc33","#ffb347"]];var blue=[["#2196F3","#ffffff"],["#ffffff","#2196F3"],["#B3E5FC","#3F51B5"],["#3F51B5","#B3E5FC"]];var blue2=[["#2196F3","#00BCD4"],["#3F51B5","#03A9F4"],["#FFC107","#673AB7"]];var green=[["#689F38","#FFF176"],["#D4E157","#558B2F"],["#8BC34A","#ffffff"],["#FFF176","#8BC34A"]];var green2=[["#ADD100","#7B920A"],["#558B2F","#FFF176"]];var red=[["#ff4b1f","#ffcfbe"],["#ff4b1f","#ff9068"],["#ff9068","#ffcfbe"],["#ff4b1f","#ff9068"],["#ff4b1f","#ffcfbe"]];var red2=[["#F44336","#F44336"],["#E91E63","#FFCA28"],["#F44336","#FFEB3B"],["#F44336","#FFCA28"]];var pink=[["#FF5F6D","#FFC371"],["#FFAFBD","#FFEDBC"]];var pinkrad=[["#FFC371","#FF5F6D"],["#FFEDBC","#FFAFBD"]];var pink2=[["#FFCC80","#E91E63"],["#E91E63","#FFCC80"]];var mono=[["#fff","#222"],["#abbaab","#fff"],["#222","#fff"],["#abbaab","#abbaab"]];var g3d=[["#ff4b1f","#1fddff"],["#4389A2","#5C258D"],["#1fddff","#ff4b1f"],["#5C258D","#4389A2"]];var purple=[["#D1C4E9","#E1F5FE"],["#7E57C2","#E1F5FE"],["#E1F5FE","#7E57C2"],["#E1F5FE","#D1C4E9"]];var purple2=[["#5C258D","#4389A2"],["#4389A2","#5C258D"]];var rainbow=[["#F44336","#E91E63"],["#9C27B0","#673AB7"],["#3F51B5","#2196F3"],["#03A9F4","#00BCD4"],["#009688","#4CAF50"],["#8BC34A","#CDDC39"],["#FFEB3B","#FFC107"],["#FF9800","#FF5722"]];
            
          
!
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