cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              div{
  background: green;
  height: 59px;
  width: 100px;
  color: white;
  text-align: center;
  padding-top: 38px;
}
            
          
!
            
              function supportsTransitions() {
    var b = document.body || document.documentElement,
        s = b.style,
        p = 'transition',
        e = {
            'Webkit'  : 'webkitTransitionEnd',
             'Moz'    : 'transitionend',
             'O'      : 'oTransitionEnd otransitionend',
             'ms'     : 'MSTransitionEnd',
             'default': 'transitionend'
        },
        v = ['Moz', 'Webkit', 'O', 'ms'];

    if (typeof s[p] == 'string') {
        return {
            prefixedProperty: p,
            prefixedEventName: e['default']
        };
    }

    p = p.charAt(0).toUpperCase() + p.substr(1);
    // Tests for vendor specific prop
    for (var i = 0; i < v.length; i++) {
        if (typeof s[v[i] + p] == 'string') {
            return {
                prefixedProperty: '-' + v[i].toLowerCase() + '-' + p.toLowerCase(),
                prefixedEventName: e[v[i]]
            };
        }
    }
    return false;
}

function animate(duration, marginLeft) {
    var css3support = supportsTransitions(),
        elm = this;
    //if(false) { //To test jQuery fallback, uncomment this line and comment out next line
    if (css3support) {
        //change duration to seconds
        duration = duration / 1000;
        elm.style[css3support.prefixedProperty] = 'margin-left ' + duration + 's linear';
        setTimeout(function () {
            elm.style.marginLeft = marginLeft;
            elm.addEventListener(css3support.prefixedEventName, function () {
                elm.style.marginLeft = 0;
            });
        }, 0);
    } else {
        //jQuery as fallback - for testing just use if(false) in above if statement
        $('div').animate({
            marginLeft: marginLeft
        }, duration, function () {
            $(this).animate({
                marginLeft: 0
            }, duration)
        });
    }
}

//animate the element
document.getElementsByTagName("div")[0].onclick = function () {
    animate.apply(this, [2000, '390px']);
}
            
          
!
999px
Loading ..................

Console