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="container">
    <p>A simple range slider with increase/decrease operators built using html/css and a little bit of js. Works on webkit browsers only.</p>
    <div class="component">
        <label class="title">My Slider</label>
        <div class="slider">
            <div class="track">
                <span class="runner"></span>
            </div>
            <input type="range" min="40" max="180" step="1" value="110" />
            <label class="start">40</label>
            <label class="end">180</label>
        </div>
        <div class="operators">
            <span class="increment">+</span>
            <span class="decrement">-</span>
        </div>
        <div class="bubble">110</div>
    </div>
</div>
              
            
!

CSS

              
                $purple: #3A2868;
$green: #77BE7D;

body {
    background: #543D8D;
    color: white;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 14px;
    padding: 10%;
}

.container {
    width: 300px;
    margin: 0 auto;
    padding: 20px 20px 10px 20px;
    background: rgba(255,255,255,0.05);
    border-radius: 3px;
}

p {
    font-weight: 400;
    font-size: 14px;
    line-height: 1.75em;
    padding-bottom: 20px;
}

.component {
    width: 100%;
    overflow: hidden;
}

.title {
    display: block;
    font-size: 12px;
    font-weight: 400;
    margin-bottom: 5px;
    text-transform: uppercase;
    clear: both;
}

.slider {
    width: 72%;
    display: inline-block;
    position: relative;
    margin-top: 10px;
    float: left;
    
    .track {
        display: block;
        background: $purple;
        width: 100%;
        height: 5px;
        border-radius: 5px;
        overflow: hidden;
        
        .runner {
            display: block;
            width: 50%;
            height: 5px;
            background: $green;
            border-radius: 5px;
        }
    }
    
    input[type="range"] {
        -webkit-appearance: none;
        background: rgba(255,255,255,0);
        width: 100%;
        padding: 0;
        margin: 0;
        position: absolute;
        top: 0;
        left: 0;
        
        &:focus {
            outline: none;
        }
        
        &::-webkit-slider-runnable-track {
            width: 100%;
            height: 5px;
        }
        
        &::-webkit-slider-thumb {
            -webkit-appearance: none;
            position: relative;
            top: -5px;
            width: 14px;
            height: 14px;
            border-radius: 50%;
            background: $green;
            @media (max-width: 480px) {
                width: 24px;
                height: 24px;
                top: -10px;
            }
        }
    }
    
    label {
        font-size: 13px;
        line-height: 2.5em;
        &.end {
            float: right;
        }
    }
}

.bubble {
    width: 15%;
    height: 35px;
    background: $green;
    border-radius: 4px;
    float: right;
    line-height: 35px;
    text-align: center;
    font-size: 18px;
    letter-spacing: -0.05em;
}

.operators {
    display: block;
    width: 20px; 
    margin-left: 5px;
    float: right;
    & > span {
        display: block;
        width: 100%;
        height: 16px;
        border-radius: 4px;
        background: $purple;
        text-align: center;
        line-height: 14px;
        margin: 0 0 4px 0;
        font-size: 15px;
    }
}
              
            
!

JS

              
                $('input[type="range"]').change(function() {
    
    var $current = parseFloat($('.bubble').text());
    var $value = parseFloat($(this).val());
    var $min = parseFloat($(this).attr('min'));
    var $max = parseFloat($(this).attr('max'));
    var $diff = Math.abs($current - $value);

    // Calculate the range value as percentage
    calc = 100 * ($value-$min) / ($max-$min);  
    
    // Update the track runner
    $('.runner').animate({width: calc + '%'}, 600);
        
    // Update the bubble
    if ($diff > 1) {
        $('.bubble').prop('Counter', $current).animate({
            Counter: $value
        }, {
            duration: 600,
            easing: 'swing',
            step: function (now) {
                $(this).text(Math.ceil(now));
            }
        });
    } else {
        $('.bubble').text($value);
    }
    
});

$('.operators > .increment').click(function() {
    var $input = $('input[type="range"]');
    var $current = parseFloat($input.val());
    $input.val($current + 1);
    $input.trigger('change');
});

$('.operators > .decrement').click(function() {
    var $input = $('input[type="range"]');
    var $current = parseFloat($input.val());
    $input.val($current - 1);
    $input.trigger('change');
});


              
            
!
999px

Console