Skip to content

Instantly share code, notes, and snippets.

@drewbrokke
Last active September 22, 2017 21:28
Show Gist options
  • Save drewbrokke/469c5a1a7b085d772367738987694e2d to your computer and use it in GitHub Desktop.
Save drewbrokke/469c5a1a7b085d772367738987694e2d to your computer and use it in GitHub Desktop.
javascript: (function() {
if (document.getElementById('snippetSlider')) {
return;
}
var body = document.querySelector("body");
var slider = document.createElement("input");
var styleTag = document.createElement("style");
var styleString = "input[type=range]#snippetSlider{-webkit-appearance:none;margin:18px 0;width:200px}input[type=range]#snippetSlider:focus{outline:0}input[type=range]#snippetSlider::-webkit-slider-runnable-track{width:200px;height:8.4px;cursor:pointer;animate:.2s;box-shadow:1px 1px 1px #000,0 0 1px #0d0d0d;background:#3071a9;border-radius:1.3px;border:.2px solid #010101}input[type=range]#snippetSlider::-webkit-slider-thumb{box-shadow:1px 1px 1px #000,0 0 1px #0d0d0d;border:1px solid #000;height:36px;width:16px;border-radius:3px;background:#fff;cursor:pointer;-webkit-appearance:none;margin-top:-14px}input[type=range]#snippetSlider:focus::-webkit-slider-runnable-track{background:#367ebd}input[type=range]#snippetSlider::-moz-range-track{width:200px;height:8.4px;cursor:pointer;animate:.2s;box-shadow:1px 1px 1px #000,0 0 1px #0d0d0d;background:#3071a9;border-radius:1.3px;border:.2px solid #010101}input[type=range]#snippetSlider::-moz-range-thumb{box-shadow:1px 1px 1px #000,0 0 1px #0d0d0d;border:1px solid #000;height:36px;width:16px;border-radius:3px;background:#fff;cursor:pointer}input[type=range]#snippetSlider::-ms-track{width:200px;height:8.4px;cursor:pointer;animate:.2s;background:0 0;border-color:transparent;border-width:16px 0;color:transparent}input[type=range]#snippetSlider::-ms-fill-lower{background:#2a6495;border:.2px solid #010101;border-radius:2.6px;box-shadow:1px 1px 1px #000,0 0 1px #0d0d0d}input[type=range]#snippetSlider::-ms-fill-upper{background:#3071a9;border:.2px solid #010101;border-radius:2.6px;box-shadow:1px 1px 1px #000,0 0 1px #0d0d0d}input[type=range]#snippetSlider::-ms-thumb{box-shadow:1px 1px 1px #000,0 0 1px #0d0d0d;border:1px solid #000;height:36px;width:16px;border-radius:3px;background:#fff;cursor:pointer}input[type=range]#snippetSlider:focus::-ms-fill-lower{background:#3071a9}input[type=range]#snippetSlider:focus::-ms-fill-upper{background:#367ebd}";
styleTag.innerHTML = styleString;
slider.setAttribute("id", "snippetSlider");
slider.setAttribute("type", "range");
slider.setAttribute("min", "300");
slider.setAttribute("max", "1000");
slider.setAttribute("value", "800");
slider.setAttribute("style", "position: fixed; top:0; right: 0");
slider.addEventListener("input", function() {
body.setAttribute("style", "margin: auto; max-width: " + slider.value + "px;")
});
body.appendChild(styleTag);
body.appendChild(slider);
body.setAttribute("style", "margin: auto; max-width: 800px;")
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment