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="app" :style="{ backgroundSize: bgSize, backgroundImage: bgImage}">
  <div class="container">
    <div class="box shadow-sm">
      <h2 class="mb-2 mt-0">Polka Dot Generator</h2>
      <div class="text-secondary mb-4">Pure CSS patterns created with CSS Gradients</div>
      <div class="sliders mb-4">
        <label>Background Size</label>
        <input type="range" min="1" max="100" class="custom-range" v-model="bgSlider">
        <label class="mt-3">Circle Size</label>
        <input type="range" min="1" max="98" v-model="circleSlider" class="custom-range">
      </div>
      <div class="colors mb-4">
        <label class="mr-2">Circle Color</label>
        <input type="color" class="mr-4" v-model="circleColor">
        <label class="mr-2">Background Color</label>
        <input type="color" class="mr-4" v-model="bgColor">
      </div>

      <button class="btn btn-primary ml-3 next-note" @click="randomizeColors">New Colors</button>
      <button class="btn btn-primary ml-3 next-note" @click="randomize">Randomize</button>
      <button class="btn btn-outline-primary ml-3 next-note" @click="copyCSS">Copy CSS</button>
      <div class="mt-4 small"><a href="http://www.gradientmagic.com" class="text-secondary" target="_blank">More Fantastic CSS Gradients</a></div>
    </div>
  </div>
</div>
<div id="copyBox"></div>
              
            
!

CSS

              
                body {
  
}


.container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  position: relative;
  .box {
    // border: 1px solid #ddd;
    background: white;
    padding: 25px 45px;
    border-radius: 10px;
    max-width: 500px;
  }
}
              
            
!

JS

              
                // https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
function componentToHex(c) {
 var hex = c.toString(16);
 return hex.length == 1 ? "0" + hex : hex;
}

function rgbToHex(r, g, b) {
 return "#" + this.componentToHex(r) + this.componentToHex(g) + this.componentToHex(b);
} 

// [0, max)
function getRandomInt(max) {
    return Math.floor(Math.random() * Math.floor(max));
}

function randomColorStringHex(){
  let r = getRandomInt(256);
  let g = getRandomInt(256);
  let b = getRandomInt(256); 

  return rgbToHex(r,g,b);
}

// https://stackoverflow.com/questions/985272/selecting-text-in-an-element-akin-to-highlighting-with-your-mouse
function selectText(node) {
    node = document.getElementById(node);

    if (document.body.createTextRange) {
        const range = document.body.createTextRange();
        range.moveToElementText(node);
        range.select();
    } else if (window.getSelection) {
        const selection = window.getSelection();
        const range = document.createRange();
        range.selectNodeContents(node);
        selection.removeAllRanges();
        selection.addRange(range);
    } else {
        console.warn("Could not select text in node: Unsupported browser.");
    }
}

var chrome = VueColor.Chrome;

var vm = new Vue({
  el: "#app",
  data: {
    bgSlider: 50,
    circleSlider: 50,
    circleColor: "#f94040",
    bgColor: "#ffffff",
    colors: '#194d33',
    showBGPicker: false,
  },
  components: {
    'chrome-picker': chrome
  },
  computed: {
    bgSize(){
      let size = Math.floor((this.bgSlider/100) * 500);
      return `${size}px ${size}px`
    },
    bgImage(){
      console.log(this.circleSlider);
      
      let smoothingConstant = 2;
      if(this.bgSlider < 15 || this.bgSlider > 85) smoothingConstant = 1;
      if(this.bgSlider < 4 || this.bgSlider > 96) smoothingConstant = 0; 
      
      return `radial-gradient(circle at center center, ${this.circleColor} ${this.circleSlider}%, ${this.bgColor} ${parseInt(this.circleSlider) + smoothingConstant}%)`
    },
    fullCSS(){
      return `background-image: ${this.bgImage}; background-size: ${this.bgSize};`
    }
  },
  methods: {
    randomize(){
      this.bgSlider = Math.floor(Math.random() * 100);
      this.circleSlider = Math.floor(Math.random() * 100);
      this.randomizeColors();
    },
    randomizeColors(){
      this.bgColor = randomColorStringHex();
      this.circleColor = randomColorStringHex();
    },
    copyCSS(){
      let copyBox = document.querySelector('#copyBox');
      copyBox.style['display'] = 'block';
      copyBox.innerHTML = this.fullCSS;
      selectText('copyBox')
      document.execCommand('copy');
      copyBox.style['display'] = 'none';
      toastr.success('CSS Copied to Clipboard')
    },
    updateColor(newVal){
      console.log(newVal);
      this.bgColor = newVal.hex;
    }
  },
  created(){
    this.randomize();
  },
});


              
            
!
999px

Console