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 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="mainContainer">
  <div class="topBorder"></div>
  <div class="bottomBorder"></div>
</div>
              
            
!

CSS

              
                body{
  background:#0f222b;
  color: white;
}

.mainContainer{
  background:#333;
  /* Set the container width and height, if you change it, you have to reload to see it take effect */
  width:20%;
  height:200px;
  margin:auto;
  margin-top:100px;
  position:relative;
}

.topBorder{
    width: 100%;
    height: 100%;
    position: absolute;
    border:2px solid #5db8ff;
    box-sizing: border-box;
    /* Currently the original clip needs to be set in the css as otherwise the function does not work in jquery. However, this will not work well with responsiveness if you try to set distinct values at the start.*/
    clip: rect(0px,0px,0px,0px);
}

.bottomBorder{
    width: 100%;
    height: 100%;
    position: absolute;
    border:2px solid #5db8ff;
    box-sizing: border-box;
    clip: rect(0px,0px,0px,0px);
}
              
            
!

JS

              
                
var topBorderWidth = $('.topBorder').outerWidth();
var topBorderHeight = $('.topBorder').outerHeight();

/* Plugin from Joshua Poehls and originally Jim Palmer, to give support clip in jquery .animate function */

/*
* jquery.animate.clip.js
*
* jQuery css clip animation support -- Joshua Poehls
* version 0.1.4

* forked from Jim Palmer's plugin http://www.overset.com/2008/08/07/jquery-css-clip-animation-plugin/
* idea spawned from jquery.color.js by John Resig
* Released under the MIT license.
*/
(function (jQuery) {

    function getStyle(elem, name) {
        return (elem.currentStyle && elem.currentStyle[name]) || elem.style[name];
    }

    function getClip(elem) {
        var cssClip = jQuery(elem).css('clip') || '';

        if (!cssClip) {
            // Try to get the clip rect another way for IE8.
            // This is a workaround for jQuery's css('clip') returning undefined
            // when the clip is defined in an external stylesheet in IE8. -JPOEHLS
            var pieces = {
                top: getStyle(elem, 'clipTop'),
                right: getStyle(elem, 'clipRight'),
                bottom: getStyle(elem, 'clipBottom'),
                left: getStyle(elem, 'clipLeft')
            };

            if (pieces.top && pieces.right && pieces.bottom && pieces.left) {
                cssClip = 'rect(' + pieces.top + ' ' + pieces.right + ' ' + pieces.bottom + ' ' + pieces.left + ')';
            }
        }

        // Strip commas and return.
        return cssClip.replace(/,/g, ' ');
    }

    jQuery.fx.step.clip = function (fx) {
        if (fx.pos === 0) {
            var cRE = /rect\(([0-9\.]{1,})(px|em)[,]?\s+([0-9\.]{1,})(px|em)[,]?\s+([0-9\.]{1,})(px|em)[,]?\s+([0-9\.]{1,})(px|em)\)/;

            fx.start = cRE.exec(getClip(fx.elem));
            if (typeof fx.end === 'string') {
                fx.end = cRE.exec(fx.end.replace(/,/g, ' '));
            }
        }
        if (fx.start && fx.end) {
            var sarr = new Array(), earr = new Array(), spos = fx.start.length, epos = fx.end.length,
                emOffset = fx.start[ss + 1] == 'em' ? (parseInt($(fx.elem).css('fontSize')) * 1.333 * parseInt(fx.start[ss])) : 1;
            for (var ss = 1; ss < spos; ss += 2) { sarr.push(parseInt(emOffset * fx.start[ss])); }
            for (var es = 1; es < epos; es += 2) { earr.push(parseInt(emOffset * fx.end[es])); }
            fx.elem.style.clip = 'rect(' +
                parseInt((fx.pos * (earr[0] - sarr[0])) + sarr[0]) + 'px ' +
                parseInt((fx.pos * (earr[1] - sarr[1])) + sarr[1]) + 'px ' +
                parseInt((fx.pos * (earr[2] - sarr[2])) + sarr[2]) + 'px ' +
                parseInt((fx.pos * (earr[3] - sarr[3])) + sarr[3]) + 'px)';
        }
    }
})(jQuery);

/* Code to actually animate the borders */

var IntervalTimer = 1;
varAnmiSpeed = 1000;
setInterval(function(){
  $( window ).resize(function() {
    var topBorderWidth = $('.topBorder').outerWidth();
    var topBorderHeight = $('.topBorder').outerHeight();
  });
  $('.topBorder').animate({'clip':'rect(0px '+topBorderWidth+'px '+(topBorderHeight-topBorderHeight+2)+'px 0px)'}, varAnmiSpeed);
  $('.topBorder').animate({'clip':'rect(0px '+topBorderWidth+'px '+(topBorderHeight)+'px '+(topBorderWidth-2)+'px)'}, varAnmiSpeed);
  $('.topBorder').animate({'clip':'rect('+(topBorderHeight-2)+'px '+topBorderWidth+'px '+(topBorderHeight)+'px 0px)'}, varAnmiSpeed);
  $('.topBorder').animate({'clip':'rect(0px '+(topBorderWidth-topBorderWidth+2)+'px '+(topBorderHeight)+'px 0px)'}, varAnmiSpeed)
  
  $('.bottomBorder').animate({'clip':'rect('+(topBorderHeight-2)+'px '+topBorderWidth+'px '+(topBorderHeight)+'px 0px)'}, varAnmiSpeed);
  $('.bottomBorder').animate({'clip':'rect(0px '+(topBorderWidth-topBorderWidth+2)+'px '+(topBorderHeight)+'px 0px)'}, varAnmiSpeed)
  $('.bottomBorder').animate({'clip':'rect(0px '+topBorderWidth+'px '+(topBorderHeight-topBorderHeight+2)+'px 0px)'}, varAnmiSpeed);
  $('.bottomBorder').animate({'clip':'rect(0px '+topBorderWidth+'px '+(topBorderHeight)+'px '+(topBorderWidth-2)+'px)'}, varAnmiSpeed);
  
  IntervalTimer = varAnmiSpeed * 4;
}, IntervalTimer);
              
            
!
999px

Console