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="tone_container">
  <img id="tone_image" src="" alt="Background" data-valid="false" />
  <div id="tone_gray" class="tone"></div>
  <div id="tone_minus" class="tone"></div>
  <div id="tone_add" class="tone"></div>
</div>

<div class="controls">
  <ul id="tone_change">
    <li>
      <label for="input_tone_red">
        <span class="color icon name" id="name_tone_red">Red:</span>
        <input type="number" value="0" min="-255" max="255" id="input_tone_red" class="input_tone" oninput="tone_check()" />
      </label>
    </li>
    <li>
      <label for="input_tone_green">
        <span class="color icon name" id="name_tone_green">Green:</span>
        <input type="number" value="0" min="-255" max="255" id="input_tone_green" class="input_tone" oninput="tone_check()" />
      </label>
    </li>
    <li>
      <label for="input_tone_blue">
        <span class="color icon name" id="name_tone_blue">Blue:</span>
        <input type="number" value="0" min="-255" max="255" id="input_tone_blue" class="input_tone" oninput="tone_check()" />
      </label>
    </li>
    <li>
      <label for="input_tone_gray">
        <span class="color icon name" id="name_tone_gray">Gray:</span>
        <input type="number" value="0" min="0" max="255" id="input_tone_gray" class="input_tone" oninput="tone_check()" />
      </label>
    </li>
  </ul>
  <ul id="background_change">
    <li>
      <label for="input_bg_url">
        <span class="icon name">Background URL:</span>
        <input type="text" size="20" value="http://" id="input_bg_url" data-input="false" onblur="url_blurred();" onfocus="url_focused();" oninput="url_check(this.value)" />
      </label>
    </li>
  </ul>
</div>
              
            
!

CSS

              
                #tone_container {
  border: 1px solid #000;
  position: relative;
  display: inline-block;
  margin-bottom: 64px;
}
.tone {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
#tone_gray {
  background: rgb(255, 255, 255);
  mix-blend-mode: hue;
  opacity: 0;
}
#tone_minus {
  background: rgb(255, 255, 255);
  mix-blend-mode: multiply;
}
#tone_add {
  background: rgb(0, 0, 0);
  mix-blend-mode: screen;
}

/* Presentational stuff */
#tone_container img {
  display: inline;
  height: auto;
  width: auto;
  font-family: "Helvetica Neue", "Helvetica", Arial, sans-serif;
  vertical-align: top;
}
#tone_container img[data-valid="false"] {
  background: #ccc;
  background: linear-gradient(to top, #000, rgba(128, 128, 128, 0), #fff), linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
  display: inline-block;
  width: 320px;
  height: 240px;
  font-size: 0;
  position: relative;
}
#tone_container img[data-valid="false"]:after {
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  content: "Invalid image";
  font-size: 20px;
  position: absolute;
  top: 0;
  left: 0;
  margin: 8px 8px;
  padding: 4px 12px;
}
.controls {
  background: rgba(0, 0, 0, 0.8);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 -1px 0 #000;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%; 
}
.controls ul {
  padding: 0;
  margin: 0;
}
.controls li {
  padding: 2px 8px;
  display: inline-block;
}
.controls .name {
  display: inline-block;
  cursor: pointer;
  margin-right: 8px;
  vertical-align: top;
}
.controls .icon {
  color: transparent;
  font-size: 0;
  overflow: hidden;
  height: 16px;
  width: 16px;
}
.controls .color {
  background-image: linear-gradient(to top, rgba(0, 0, 0, 0), #000);
  border: 1px solid #fff;
  box-shadow: 0 0 0 1px #000, inset 0 0 0 1px #000;
  border-radius: 32px;
}
#name_tone_red { background-color: #f00; }
#name_tone_green { background-color: #0f0; }
#name_tone_blue { background-color: #00f; }
#name_tone_gray { background-color: gray; }
.input_tone { width: 64px; vertical-align: top; }

#background_change .icon {
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
  border: 1px solid #fff;
  border-radius: 2px;
  box-shadow: 0 0 0 1px #000, inset 0 0 0 1px rgba(0, 0, 0, 0.6);
}
              
            
!

JS

              
                var tone = { red: 0, green: 0, blue: 0, gray: 0 }
var colors_add = { red: 0, green: 0, blue: 0 }
var colors_sub = { red: 255, green: 255, blue: 255 }
var colors_gray = 0

function tone_check() {
  tone.red = tone_input_check(document.getElementById('input_tone_red').value);
  tone.green = tone_input_check(document.getElementById('input_tone_green').value);
  tone.blue = tone_input_check(document.getElementById('input_tone_blue').value);
  tone.gray = tone_input_check_gray(document.getElementById('input_tone_gray').value);
  document.getElementById('input_tone_gray').value = tone.gray;
  tone_calculate(tone.red, tone.green, tone.blue, tone.gray);
  tone_adjust_background();
}

function tone_input_check(value) {
  if (value > 255) {
    return 255
  } else if (value < -255) {
    return -255
  } else if (value => -255 && value <= 255) {
    return value
  } else {
    return "-"
  }
}
function tone_input_check_gray(value) {
  if (parseInt(value) > 255) {
    return 255
  } else if (parseInt(value) < 0) {
    return 0
  } else {
    return value
  }
}

function tone_calculate(val_red, val_green, val_blue, val_gray) {
	val_red = tone_calculate_value(val_red)
	val_green = tone_calculate_value(val_green)
	val_blue = tone_calculate_value(val_blue)
	val_gray = tone_calculate_gray(val_gray)
	colors_add.red 	= val_red.add;
	colors_add.green = val_green.add;
	colors_add.blue 	= val_blue.add;
	colors_sub.red = val_red.sub;
	colors_sub.green = val_green.sub;
	colors_sub.blue = val_blue.sub;
	colors_gray = val_gray;
}

function tone_calculate_value(value) {
	ary = {sub: 0, add: 0};
	if (parseInt(value) < 0) {
		ary.sub = (255 + parseInt(value));
		ary.add = 0;
	} else if (parseInt(value) >= 0) {
		ary.sub = 255;
		ary.add = parseInt(value);
	}
	return ary
}
function tone_calculate_gray(value) { return ((100 / 255) * 0.01) * value }

function tone_adjust_background() {
	document.getElementById("tone_gray").style.opacity = colors_gray;
  document.getElementById("tone_minus").style.backgroundColor = 'rgb(' + colors_sub.red + ',' + colors_sub.green + ',' + colors_sub.blue + ')';
	document.getElementById("tone_add").style.backgroundColor = 'rgb(' + colors_add.red + ',' + colors_add.green + ',' + colors_add.blue + ')';
}

function url_check(value) {
  e = document.getElementById("input_bg_url")
  i = document.getElementById("tone_image")
  if (e.dataset.input == "true") {
    regex = new RegExp("^(http[s]?:\\/\\/(www\\.)?|ftp:\\/\\/(www\\.)?|www\\.){1}([0-9A-Za-z-\\.@:%_\+~#=]+)+((\\.[a-zA-Z]{2,3})+)(/(.)*)?(\\?(.)*)?");
    if(regex.test(value)){
      // Matches regex
      e.dataset.valid = "true";
      i.dataset.valid = "true";
      i.src = e.value;
    } else {
      // Doesn't match regex
      e.dataset.valid = "false";
      i.dataset.valid = "false";
      i.src = ""
    }
  }
}
function url_focused() {
  e = document.getElementById("input_bg_url");
  if (e.dataset.input == "false") {
    e.dataset.input = "true";
    e.value = "";
	}
}
function url_blurred() {
  e = document.getElementById("input_bg_url");
  if (e.dataset.input == "true" && e.value == "") {
    e.dataset.input = "false";
    e.value = "http://";
	}
}
              
            
!
999px

Console