Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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 class="center-xy">
    <h1>Slide to Unlock</h1>
    <input type="range" value="0" class="pullee" />
</div>
              
            
!

CSS

              
                $size: 32;

@mixin track($color: red, $radius: 0) {
    &::-webkit-slider-runnable-track {
        @content;
        border-radius: $radius;
        background-color: $color;
    }
    &::-moz-range-track {
        @content;
        border-radius: $radius;
        background-color: $color;
    }
    &::-moz-focus-outer {
        border: 0;
    }
    &::-ms-track {
        border: 0;
        @content;
        border-radius: $radius;
        background-color: $color;
        color: transparent;
    }
    &::-ms-fill-lower, &::-ms-fill-upper {
        background-color: transparent;
    }
    &::-ms-tooltip {
        display: none;
    }
}

@mixin thumb() {
    &::-webkit-slider-thumb {
        appearance: none;
        @content;
    }
    &::-moz-range-thumb {
        border: 0;
        @content;
    }
    &::-ms-thumb {
        @content;
    }
}

.pullee {
    width: 10rem;
    appearance: none;
    
    // handle active states
    &:active {
        @include thumb() {
            transform: scale(1.1);
            cursor: -webkit-grabbing;
            cursor: -moz-grabbing;
        }
    }
    
    // accessibility
    &:focus {
        outline: none;
    }

    // thumb styles
    @include thumb() {
        display: block;
        width: 1rem;
        height: 1rem;
        border-radius: 50%;
        background: #5990DD;
        transform-origin: 50% 50%;
        transform: scale(1);
        transition: transform ease-out 100ms;
        cursor: -webkit-grab;
        cursor: -moz-grab;
    }
    
    // track styles
    @include track(#DDE0E3, 1rem) {
        height: 1rem;
        padding: .25rem;
        box-sizing: content-box;
    }
}

html {
    font-size: $size + px;
    text-align: center;
}

h1 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1.25px;
}

.center-xy {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
              
            
!

JS

              
                var inputRange = document.getElementsByClassName('pullee')[0],
    maxValue = 150, // the higher the smoother when dragging
    speed = 12, // thanks to @pixelass for this
    currValue, rafID;

// set min/max value
inputRange.min = 0;
inputRange.max = maxValue;

// listen for unlock
function unlockStartHandler() {
    // clear raf if trying again
    window.cancelAnimationFrame(rafID);
    
    // set to desired value
    currValue = +this.value;
}

function unlockEndHandler() {
    
    // store current value
    currValue = +this.value;
    
    // determine if we have reached success or not
    if(currValue >= maxValue) {
        successHandler();
    }
    else {
        rafID = window.requestAnimationFrame(animateHandler);
    }
}

// handle range animation
function animateHandler() {
    
    // update input range
    inputRange.value = currValue;
    
    // determine if we need to continue
    if(currValue > -1) {
    	window.requestAnimationFrame(animateHandler);   
    }
    
    // decrement value
    currValue = currValue - speed;
}

// handle successful unlock
function successHandler() {
    alert('unlocked');
    
    // reset input range
    inputRange.value = 0;
};

// bind events
inputRange.addEventListener('mousedown', unlockStartHandler, false);
inputRange.addEventListener('mousestart', unlockStartHandler, false);
inputRange.addEventListener('mouseup', unlockEndHandler, false);
inputRange.addEventListener('touchend', unlockEndHandler, false);
              
            
!
999px

Console