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

              
                <div id="generator">
  <h1>Blurred Background Generator</h1>
  <div>
    <div class="colorBoxSurround">
      <div class="label">Colour 1:</div>
      <div class="baseColorBox color-box"></div>
    </div>
    <div class="colorBoxSurround">
      <div class="label">Colour 2:</div>
      <div class="color1Box color-box"></div>
    </div>
    <div class="colorBoxSurround">
      <div class="label">Colour 3:</div>
      <div class="color2Box color-box"></div>
    </div>
    <div class="colorBoxSurround last">
      <div class="label">Colour 4:</div>
      <div class="color3Box color-box"></div>
    </div>
  </div>
  <div class="blurrer">
    <div class="label">Blur Amount:</div>
    <input type="range" name="points" id="blur_amount" value="50" min="50" max="100">
  </div>

  <input type="submit" id="refresh" class="button" value="Generate from Selected Colours">
  <input type="submit" id="randomise" class="button" value="Randomise with new Colours">

  <textarea id="codeOutput"></textarea>

  <input type="submit" id="copy_code" class="button" value="Copy Script to Clipboard">
</div>
              
            
!

CSS

              
                /*============== Background Styles ==================*/

#blurredBackgroundContainer {
  position: absolute;
  top: 0%;
  left: 0%;
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
}

#blurredBackground {
  position: absolute;
  top: -5%;
  left: -5%;
  display: block;
  min-width: 110%;
  min-height: 110%;
  filter: blur(50px);
  -webkit-filter: blur(50px);
}

#contentContainer {
  position: absolute;
  top: 0%;
  left: 0%;
  width: 100%;
  height: 100%;
  display: block;
  overflow: scroll;
}

.color-blur {
  width: 200%;
  height: 150%;
  display: block;
  position: absolute;
  border-radius: 50%;
}
/*============== Generator Styles ==================*/

#codeOutput {
  width: 99.4%;
  height: 8em;
  margin-top: 0.5em;
}

#generator {
  width: 50%;
  background: #25252F;
  color: #f3f3f3;
  padding: 1em;
  font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
  font-width: 100;
  overflow-x: hidden;
  overflow-y: auto;
}

.label {
  vertical-align: middle !important;
  margin: 0.5em 0;
}

.color-box {
  cursor: pointer;
  height: 1em;
  padding: 0.2em;
  margin: 0.2em 0;
  border: 1px solid white;
}

.colorBoxSurround {
  width: 24%;
  float: left;
  margin: 0em 1.3% 0.2em 0%;
  
}

.last {
  margin-right: 0%;
}

.button {
  padding: 0.5em 0%;
  background: #25252F;
  color: #F3F3F3;
  border: 1px solid white;
  margin: 0.5em 0;
  width: 50%;
  cursor: pointer;
  float: left;
}

#refresh {
  margin-right: 1%;
  width: 49%;
}

#randomise {
  margin-left: 1%;
  width: 49%;
}

#copy_code {
  width: 100%;
}

h1 {
  text-align: center;
}

#blur_amount {
  width: 99.7%;
  resize: none;
}
              
            
!

JS

              
                /**
 * @author Apalis
 * @version 0.9
 */

new BlurredBackground();

function BlurredBackground() {
  var baseColor = "#3264c8";
  var color1 = "";
  var color2 = "";
  var color3 = "";

  $(function constructor() {
    $('#generator').center();

    $("#blurredBackground").css("filter", "blur(" + $("#blur_amount").val() + "px)");
    $("#blurredBackground").css("-webkit-filter", "blur(" + $("#blur_amount").val() + "px)");

    $('body').wrapInner('<div id="contentContainer"></div>')
      .prepend('<div id="blurredBackgroundContainer"></div>');

    $('#blurredBackgroundContainer').prepend('<div id="blurredBackground"></div>');

    $('#blurredBackground').append('<div class="colorBlur1 color-blur"></div>')
      .append('<div class="colorBlur2 color-blur"></div>')
      .append('<div class="colorBlur3 color-blur"></div>');

    randomise();
    eventHandlers();
    generateScript();

  });

  jQuery.fn.gradient = function(color1, gradientType, alpha) {
    this.css('background', color1);

    var gradientProperties = (gradientType == "linear") ? Math.floor((Math.random() * 100) + 1) + "deg, " : "at 50% 50%, ";

    var W3C = gradientType + "-gradient(" + gradientProperties + color1 + " 0%, " + shader(color1, Math.floor((Math.random() * 100) + 1), alpha) + " 100%)";

    this.css('background', W3C);

    return this;
  };

  jQuery.fn.center = function() {
    this.css("position", "absolute");
    this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) +
      $(window).scrollTop()) + "px");
    this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) +
      $(window).scrollLeft()) + "px");
    return this;
  };

  function randomise() {
    baseColor = '#' + (Math.random() * 0xFFFFFF << 0).toString(16);
    color1 = '#' + (Math.random() * 0xFFFFFF << 0).toString(16);
    color2 = '#' + (Math.random() * 0xFFFFFF << 0).toString(16);
    color3 = '#' + (Math.random() * 0xFFFFFF << 0).toString(16);
    setCSS();
  }

  function setCSS() {
    var min = -100;
    var max = 100;

    $('.baseColorBox').css('background-color', baseColor);
    $('.color1Box').css('background-color', color1);
    $('.color2Box').css('background-color', color2);
    $('.color3Box').css('background-color', color3);

    $('#blurredBackground').gradient(baseColor, "linear", 1);

    $('.colorBlur1').css({
      "top": Math.floor(Math.random() * (max - min + 1) + min) + "%",
      "left": Math.floor(Math.random() * (max - min + 1) + min) + "%"
    }).gradient(color1, "radial", Math.floor((Math.random() * 2) + 1), 0.5);

    $('.colorBlur2').css({
      "top": Math.floor(Math.random() * (max - min + 1) + min) + "%",
      "left": Math.floor(Math.random() * (max - min + 1) + min) + "%"

    }).gradient(shader(color2, Math.floor(Math.random() * (30 - (-30) + 1) + (-30)), 0.4), "radial", Math.floor((Math.random() * 2) + 1), 0.7);

    $('.colorBlur3').css({
      "top": Math.floor(Math.random() * (max - min + 1) + min) + "%",
      "left": Math.floor(Math.random() * (max - min + 1) + min) + "%"
    }).gradient(shader(color3, Math.floor(Math.random() * (30 - (-30) + 1) + (-30)), 0.4), "radial", Math.floor((Math.random() * 2) + 1), 0.7);
  }

  function shader(color, percentage, alpha, toHex) {
    color = color.substring(0, 1) != "#" ? "#" : "" + color;
    color = color.length == 4 ? "#" + color.substring(1, 2) + color.substring(1, 2) + color.substring(2, 3) + color.substring(2, 3) + color.substring(3, 4) + color.substring(3, 4) : color;

    var R = parseInt(color.substring(1, 3), 16);
    var G = parseInt(color.substring(3, 5), 16);
    var B = parseInt(color.substring(5, 7), 16);

    if (percentage > 0) {
      R = R + (R * (percentage / 100)) > 255 ? 255 : R + (R * (percentage / 100));
      G = G + (G * (percentage / 100)) > 255 ? 255 : G + (G * (percentage / 100));
      B = B + (B * (percentage / 100)) > 255 ? 255 : B + (B * (percentage / 100));
    } else {
      R = R + (R * (percentage / 100)) < 0 ? 0 : R + (R * (percentage / 100));
      G = G + (G * (percentage / 100)) < 0 ? 0 : G + (G * (percentage / 100));
      B = B + (B * (percentage / 100)) < 0 ? 0 : B + (B * (percentage / 100));
    }

    function changeToHex(decimal) {
      var hex = parseInt(decimal, 10).toString(16);
      return hex.length == 1 ? "0" + hex : hex;
    }
    if (toHex) {
      return "#" + changeToHex(R) + changeToHex(G) + changeToHex(B);
    } else {
      return "rgba(" + Math.round(R) + "," + Math.round(G) + "," + Math.round(B) + "," + alpha + ")";
    }
  }

  function eventHandlers() {
    $('.baseColorBox').colpick({
      colorScheme: 'dark',
      layout: 'rgbhex',
      color: baseColor,
      onChange: function(hsb, hex, rgb, el) {
        baseColor = '#' + hex;
        $(el).css('background-color', baseColor);
        setCSS();
      },
      onSubmit: function(hsb, hex, rgb, el) {
        baseColor = '#' + hex;
        $(el).css('background-color', baseColor);
        setCSS();
        $(el).colpickHide();
      }
    });

    $('.color1Box').colpick({
      colorScheme: 'dark',
      layout: 'rgbhex',
      color: color1,
      onChange: function(hsb, hex, rgb, el) {
        color1 = '#' + hex;
        $(el).css('background-color', color1);
        setCSS();
      },
      onSubmit: function(hsb, hex, rgb, el) {
        color1 = '#' + hex;
        $(el).css('background-color', color1);
        setCSS();
        $(el).colpickHide();
      }
    });

    $('.color2Box').colpick({
      colorScheme: 'dark',
      layout: 'rgbhex',
      color: color2,
      onChange: function(hsb, hex, rgb, el) {
        color2 = '#' + hex;
        $(el).css('background-color', color2);
        setCSS();
      },
      onSubmit: function(hsb, hex, rgb, el) {
        color2 = '#' + hex;
        $(el).css('background-color', color2);
        setCSS();
        $(el).colpickHide();
      }
    });

    $('.color3Box').colpick({
      colorScheme: 'dark',
      layout: 'rgbhex',
      color: color3,
      onChange: function(hsb, hex, rgb, el) {
        color3 = '#' + hex;
        $(el).css('background-color', color3);
        setCSS();
      },
      onSubmit: function(hsb, hex, rgb, el) {
        color3 = '#' + hex;
        $(el).css('background-color', color3);
        setCSS();
        $(el).colpickHide();
      }
    });

    $("#refresh").click(function(evt) {
      setCSS();
      generateScript();
    });

    $("#randomise").click(function(evt) {
      randomise();
      generateScript();
    });

    $("#blur_amount").change(function(evt) {
      console.log($(this).val());
      $("#blurredBackground").css("filter", "blur(" + $(this).val() + "px)");
      $("#blurredBackground").css("-webkit-filter", "blur(" + $(this).val() + "px)");

      generateScript();
    });

    $('#copy_code').on('click', function(event) {
      var textarea = $('#codeOutput');
      textarea.select();

      try {
        var successful = document.execCommand('copy');
        var msg = successful ? 'successful' : 'unsuccessful';
        console.log('Copying text command was ' + msg);
      } catch (err) {
        console.log('Unfortunately the copy process was unsuccessful.');
      }
    });
  }

  function generateScript() {
    var generatedScript;
    $.get("css/backgroundStyles.css", function(data) {
      console.log(JSON.stringify(data));
    });

    generatedScript = '<style type="text/css">' + "\n";

    generatedScript += "#blurredBackgroundContainer{position:absolute;top:0;left:0;width:100%;height:100%;display:block;overflow:hidden}#blurredBackground{position:absolute;top:-5%;left:-5%;display:block;min-width:110%;min-height:110%;filter:blur(" + $('#blur_amount').val() + "px);-webkit-filter:blur(" + $('#blur_amount').val() + "px)}#contentContainer{position:absolute;top:0;left:0;width:100%;height:100%;display:block;overflow:scroll}.color-blur{width:200%;height:150%;display:block;position:absolute;border-radius:50%}" + "\n";

    generatedScript +=
      '</style>' +
      '\n' +
      '<script type="text/javascript">' + "\n" +
      '   window.onload = function(){' + "\n" +
      '      var contentContainer = document.createElement("div");' + "\n" +
      '      var blurredBackgroundContainer = document.createElement("div");' + "\n" +
      '      var blurredBackground = document.createElement("div");' + "\n" +
      '      var colorBlur1 = document.createElement("div");' + "\n" +
      '      var colorBlur2 = document.createElement("div");' + "\n" +
      '      var colorBlur3 = document.createElement("div");' + "\n" +
      '\n' +
      '      contentContainer.setAttribute("id","contentContainer");' + "\n" +
      '      blurredBackground.setAttribute("id","blurredBackground");' + "\n" +
      '      blurredBackgroundContainer.setAttribute("id","blurredBackgroundContainer");' + "\n" +
      '      colorBlur1.setAttribute("class","colorBlur1 color-blur");' + "\n" +
      '      colorBlur2.setAttribute("class","colorBlur1 color-blur");' + "\n" +
      '      colorBlur3.setAttribute("class","colorBlur1 color-blur");' + "\n" +
      '      document.body.appendChild(contentContainer);' + "\n" +
      '      while(document.body.firstChild !== contentContainer)' + "\n" +
      '      {' + "\n" +
      '          contentContainer.appendChild(document.body.firstChild);' + "\n" +
      '      }' + "\n" +
      '      document.body.insertBefore(blurredBackgroundContainer, document.body.firstChild);' + "\n" +
      '      blurredBackgroundContainer.appendChild(blurredBackground);' + "\n" +
      '      blurredBackground.appendChild(colorBlur1);' + "\n" +
      '      blurredBackground.appendChild(colorBlur2);' + "\n" +
      '      blurredBackground.appendChild(colorBlur3);' + "\n" +
      '\n' +
      '      blurredBackground.setAttribute("style", "' + $('#blurredBackground').attr("style") + '");' + "\n" +
      '      colorBlur1.setAttribute("style", "' + $('.colorBlur1').attr("style") + '");' + "\n" +
      '      colorBlur2.setAttribute("style", "' + $('.colorBlur2').attr("style") + '");' + "\n" +
      '      colorBlur3.setAttribute("style", "' + $('.colorBlur3').attr("style") + '");' + "\n" +
      "   }" + "\n" +
      "</scr" + "ipt>";

    $('#codeOutput').val(generatedScript);
  }

}
              
            
!
999px

Console