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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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="battery onscreen">
    <div class="bubbles battery-bubbles">
        <span>&nbsp;</span>
    </div>
    <div class="liquid liquid-bg-color">
        <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="300px" height="5px" viewBox="0 0 300 5" enable-background="new 0 0 300 5" xml:space="preserve">
            <path fill="#00fa57" class="wave" d="M300,300V2.5c0,0-0.6-0.1-1.1-0.1c0,0-25.5-2.3-40.5-2.4c-15,0-40.6,2.4-40.6,2.4
            c-12.3,1.1-30.3,1.8-31.9,1.9c-2-0.1-19.7-0.8-32-1.9c0,0-25.8-2.3-40.8-2.4c-15,0-40.8,2.4-40.8,2.4c-12.3,1.1-30.4,1.8-32,1.9
            c-2-0.1-20-0.8-32.2-1.9c0,0-3.1-0.3-8.1-0.7V300H300z" />
        </svg>
    </div><!-- .liquid -->
</div>
<div class="battery-text onscreen">
    <span class="percentage"></span><small class="units"></small>
</div>
<div class="slider onscreen">
    <input value="0" class="vertical pointer" type="range" name="percentage" min="0" max="100" step="1" orient="vertical">
</div>
<div class="page-spacer"></div>
<div class="bubbles bottom-bubbles">
    <span>&nbsp;</span>
</div>
              
            
!

CSS

              
                small { font-size: .7em }
svg { display: block }
.page-spacer {
    min-height: 171px;
    height: calc(100% - 160px);
}
.battery-text {
    width: 80px;
    height: 160px;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-color: #fff;
    background-image: linear-gradient(#fff 50%, #c3c3c3 0%);
    background-repeat: repeat;
    background-size: 100% 200%;
    transition: background-position .5s ease, opacity .5s ease;
    opacity: 0;
    z-index: 2;
}
.battery,
.battery-text,
.slider {
    margin: 0 auto;
    position: absolute;
    line-height: 6.38em;
    text-align: center;
    font-size: 1.5em;
    color: white;
    font-family: Ebrima;
    top: calc(50% - 155px);
    left: calc(50% - 39.5px);
}
.pointer { cursor: pointer }
.battery {
    border: 5px solid #00fa57;
    height: 150px;
    border-radius: 1px;
    width: 70px;
    background-color: #00fa57;
    background-image: linear-gradient(#00fa57 50%, #444 0%);
    background-repeat: repeat;
    background-size: 100% 200%;
    background-position: 0 -100%;
    transition: background-position .5s ease;
}
.battery::after {
    background-color: #00fa57;
    content: '';
    display: block;
    height: 10px;
    position: absolute;
    right: 20px;
    top: -15px;
    width: 30px;
    border-top: 1px solid transparent;
    border-bottom: 1px solid transparent;
    border-top-left-radius: 1px;
    border-top-right-radius: 1px;
}
.bubbles {
    display: inline-block;
    position: relative;
}
.battery-bubbles {
    width: 69px;
    left: calc(50% - 35px);
    height: 149px;
}
.bottom-bubbles {
    width: 39px;
    left: calc(50% - 20px);
    height: 150px;
}
.bubbles span {
    position: relative;
    margin: 3em 0 0; /* Height bubbles rise to */
    color: #fff;
    z-index: 2;
}
.individual-bubble {
    position: absolute;
    border-radius: 100%;
    bottom: 0;
    background-color: #00fa57;
    z-index: 1;
}
.vertical {
    writing-mode: bt-lr; /* IE */
    -webkit-appearance: slider-vertical; /* WebKit */
    width: 8px;
    height: 159.5px;
    margin: 0;
    margin-left: 95px;
}
.liquid {
    position: absolute;
    width: 70px;
    height: 5px;
    overflow: hidden;
    -webkit-backface-visibility: hidden;
    -webkit-transform: translate3d(0, 0, 0);
    -webkit-transform: translate(0, 50px);
            transform: translate(0, 50px);
    margin-top: -51px;
    transition: top .5s ease;
    display: none;
}
.wave {
    -webkit-animation-name: wave-action;
            animation-name: wave-action;
    -webkit-animation-iteration-count: infinite;
            animation-iteration-count: infinite;
    -webkit-animation-timing-function: linear;
            animation-timing-function: linear;
    -webkit-animation-duration: .8s;
            animation-duration: .8s;
    width: 70px;
    height: 5px;
    fill: #00fa57;
}
@-webkit-keyframes wave-action {
    0%   { -webkit-transform: translate(-150px, 0) }
    100% { -webkit-transform: translate(0, 0) }
}
@keyframes wave-action {
    0%   { transform: translate(-150px, 0) }
    100% { transform: translate(0, 0) }
}

/**/

@media all and (max-height: 332px){
   .onscreen { top: 11px }
}

/**/

/* Animating the top property in Microsoft Edge does not work so prevent animating it */
_:-ms-lang(x), _:-webkit-full-screen, .individual-bubble { top: inherit !important }
              
            
!

JS

              
                function changeStylesheetRule(s, selector, property, value){
    // Make these strings lowercase
    selector = selector.toLowerCase();
    value    = value.toLowerCase();

    // Delete it if it exists
    for(var i = 0; i < s.cssRules.length; i++){
        var rule = s.cssRules[i];
        if(rule.selectorText === selector){
            s.deleteRule(i);
            break;
        }
    }

    // Convert camelCase to hyphenated-case
    property = property.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
    s.insertRule(selector + " { " + property + ": " + value + "; }", 0);
}

// Function to select random array element
// Used within the setInterval()
function randomValue(arr){
    return arr[Math.floor(Math.random() * arr.length)];
}

jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend(jQuery.easing, {
    def: 'easeOutQuad',
    swing: function (x, t, b, c, d){
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },
    easeOutQuad: function (x, t, b, c, d){
        return -c * (t /= d) * (t - 2) + b;
    },
});

$(document).ready(function(){
    var perc = 50;
    var s = document.styleSheets[0];
    // Define a size array, this will be used to vary bubble sizes
    var sArray = [];

    setTimeout(function(){
        updateBattery(perc, s);
        $('.percentage').text(perc);
        $('.units').text('%');
        $('.battery-text').css('opacity', 1);
        $('.slider input').animate({ value: perc }, 500, 'easeOutQuad');

        setTimeout(function(){
            $('.liquid').show();
        }, 500);
    }, 500);

    function updateBattery(perc, s){
        if(perc === 100){
            sArray = [];
        } else if(sArray.length === 0){
            sArray = [4, 6, 8, 10];
        }

        changeStylesheetRule(s, '.battery', 'backgroundPosition', '0 -' + (100 - perc) + '% !important');
        changeStylesheetRule(s, '.battery-text', 'backgroundPosition', '0 -' + (100 - perc) + '%');
        changeStylesheetRule(s, '.liquid', 'top', (100 - perc) + '%');
        if(perc === 100){
            changeStylesheetRule(s, '.liquid-bg-color', 'backgroundColor', '#00fa57');
        } else {
            changeStylesheetRule(s, '.liquid-bg-color', 'backgroundColor', '#444');
        }
    }

    // setInterval function used to create new bubble every 350 milliseconds
    setInterval(function(){
        if(sArray.length > 0){
            // Get a random size, defined as variable so it can be used for both width and height
            var size = randomValue(sArray);

            var largestSize = Math.max.apply(Math, sArray);
            var offset = largestSize / 2; // half to get the largest bubble radius
            offset += 5; // 5px for border-right

            // New bubble appended to div with it's size and left position being set inline
            $('.bubbles').each(function(){
                var bArray = new Array(parseInt($(this).width()) - offset)
                                 .join()
                                 .split(',')
                                 .map(function(item, index){ return ++index; });

                $(this).append('<div class="individual-bubble" style="left: ' + randomValue(bArray) + 'px; width: ' + size + 'px; height: ' + size + 'px"></div>');
            });

            // Animate each bubble to the top (bottom 100%) and reduce opacity as it moves
            // Callback function used to remove finished animations from the page
            $('.individual-bubble').animate({
                'top': 0,
                'bottom': '100%',
                'opacity' : '-=0.7',
            }, 3000, function(){
                $(this).remove();
            });
        }
    }, 350);

    $('.slider input').on('input', function(){
        $(this).stop(); // Terminate any running animation
        var original = this.value;
        // Set slider back to its starting value so we can animate the change
        this.value = perc;
        perc = parseInt(original);
        $(this).animate({ value: perc }, 500, 'easeOutQuad');
        $('.percentage').text(perc);
    }).on('mouseup', function(){
        // We need to manually call this to make sure things bubble up to the change event
        $(this).trigger('change');
    }).on('change', function(){
        updateBattery(perc, s);
    });
});
              
            
!
999px

Console