Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <h1>Style Property Concept</h1>

<section>
  <div class="header">
    <button id="tween-1">Play</button>
    <div class="syntax">
      <div>TWEEN 1 - Element Style</div>
      <pre>TweenLite.to(target1, 1, { style: element1 });</pre>
    </div>
  </div>
  <div class="demo">
    <div id="element-1" class="element">element 1</div>
    <div id="target-1" class="target">target 1</div>
  </div>
</section>

<section>
  <div class="header">
    <button id="tween-2">Play</button>
    <div class="syntax">
      <div>TWEEN 2 - Blacklist Props</div>
      <pre>TweenLite.to(target2, 1, { style: element2, filterStyle: "-=backgroundColor,height" });</pre>
    </div>
  </div>
  <div class="demo">
    <div id="element-2" class="element">element 2</div>
    <div id="target-2" class="target">target 2</div>
  </div>
</section>

<section>
  <div class="header">
    <button id="tween-3">Play</button>
    <div class="syntax">
      <div>TWEEN 3 - Whitelist Props</div>
      <pre>TweenLite.to(target3, 1, { style: element3, filterStyle: "+=backgroundColor,height" });</pre>
    </div>
  </div>
  <div class="demo">
    <div id="element-3" class="element">element 3</div>
    <div id="target-3" class="target">target 3</div>
  </div>
</section>

<section>
  <div class="header">
    <button id="tween-4">Play</button>
    <div class="syntax">
      <div>TWEEN 4 - Overwrite Props</div>
      <pre>TweenLite.to(target4, 1, { style: element4, backgroundColor: "#2e8b57", rotation: -90 });</pre>
    </div>
  </div>
  <div class="demo">
    <div id="element-4" class="element">element 4</div>
    <div id="target-4" class="target">target 4</div>
  </div>
</section>

<section>
  <div class="header">
    <button id="tween-5">Play</button>
    <div class="syntax">
      <div>TWEEN 5 - CSS Rule</div>
      <pre>TweenLite.to(target5, 1, { style: ".rule-1" });</pre>
    </div>
  </div>
  <div class="demo">
    <div id="target-5" class="target">target 5</div>
    <div class="rule-box">
      <div>
        .rule-1 {<br>
        &nbsp; width: 225px;<br>
        &nbsp; height: 75px;<br>
        &nbsp; background-color: #2e8b57;<br>
        }
      </div>
    </div>
  </div>
</section>

<section>
  <div class="header">
    <button id="tween-6">Play</button>
    <div class="syntax">
      <div>TWEEN 6 - Multiple Styles</div>
      <pre>TweenLite.to(target6, 1, { style: [element6, ".rule-1", ".rule-2"], filterStyle: "-=x,y,rotation" });</pre>
    </div>
  </div>
  <div class="demo">
    <div id="element-6" class="element">element 6</div>
    <div id="target-6" class="target">target 6</div>
    <div class="rule-box">
      <div>
        .rule-1 {<br>
        &nbsp; width: 225px;<br>
        &nbsp; height: 75px;<br>
        &nbsp; background-color: #2e8b57;<br>
        }
      </div>
      <div>
        .rule-2 {<br>
        &nbsp; width: 125px;<br>
        &nbsp; height: 125px;<br>
        &nbsp; opacity: 0.5<br>
        }
      </div>
    </div>
  </div>
</section>
              
            
!

CSS

              
                body {
    margin: 40px;
    background-color: #eee;
}

*, *:before, *:after {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

h1 {
    margin-bottom: 40px;
}

button {
    background-color: darkslateblue;
    color: white;
    padding: 12px 18px;
    border: none;
    box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.3);
    cursor: pointer;
}

button:focus {
    outline: none;
}

section {
    position: relative;
    min-width: 1200px;
    margin: 0 0 75px;
    visibility: hidden;  
}

.header {
    display: flex;
    flex-direction: row;
    width: 100%;
    align-items: center;
    padding-bottom: 15px;
}

.syntax {
    flex: 1;
    margin-left: 15px;
}

.syntax div {
    font-weight: bold;
    font-size: 14px;
}

.syntax pre {
    font-size: 14px;
    margin: 4px 0 0;
}

.demo {
    border: 1px solid rgba(0, 0, 0, 0.3);
    position: relative;
    height: 250px;
}

.target,
.element {
    color: white;
    position: absolute;
    left: 0;
    top: 0;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.8);
    border: 1px solid transparent;
    outline: 1px solid transparent;
}

.target {
    background-color: cornflowerblue;
    z-index: 1;
    width: 150px;
    height: 150px;
}

.element {
    width: 100px;
    height: 100px;
    background-color: mediumvioletred;
    border-radius: 50%;
    transform: rotate(90deg);
}

.rule-box {
    display: flex;
    display: inline-flex;
    flex-direction: row;
}

.rule-box div {
    font-family: monospace;
    background-color: ghostwhite;
    box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.5);
    margin-right: 8px;
    padding: 10px;
}

.rule-1 {
    width: 225px;
    height: 75px;
    background-color: #2e8b57;
}

.rule-2 {
    width: 125px;
    height: 125px;
    opacity: 0.5;
}

              
            
!

JS

              
                
TweenLite.set(".rule-box", { x: 525, y: 75 });
TweenLite.set(".element",  { x: 400, y: 75 });
TweenLite.set(".target",   { x: 15,  y: 15 });

var cssStyle = CSSExtender();

var element1 = $("#element-1"),
    element2 = $("#element-2"),
    element3 = $("#element-3"),
    element4 = $("#element-4"),
    element6 = $("#element-6");

var target1 = $("#target-1"),
    target2 = $("#target-2"),
    target3 = $("#target-3"),
    target4 = $("#target-4"),
    target5 = $("#target-5"),
    target6 = $("#target-6");

// Extend styles
var style1 = cssStyle.extend({
  target: target1,
  styles: element1
});

var style2 = cssStyle.extend({
  target: target2,
  styles: element2,
  filter: "-=backgroundColor,height"
});

var style3 = cssStyle.extend({
  target: target3,
  styles: element3,
  filter: "+=backgroundColor,height"
});

var style4 = cssStyle.extend({
  target: target4,
  styles: element4
});

var style5 = cssStyle.extend({
  styles: ".rule-1"
});

var style6 = cssStyle.extend({
  target: target6,
  styles: [element6, ".rule-1", ".rule-2"],
  filter: "-=x,y,rotation"
});

// Add a paused property to extended styles
var tween1 = TweenLite.to(target1, 1, _.assign(style1, { paused: true }));
var tween2 = TweenLite.to(target2, 1, _.assign(style2, { paused: true }));
var tween3 = TweenLite.to(target3, 1, _.assign(style3, { paused: true }));
var tween5 = TweenLite.to(target5, 1, _.assign(style5, { paused: true }));
var tween6 = TweenLite.to(target6, 1, _.assign(style6, { paused: true }));
var tween4 = TweenLite.to(target4, 1, _.assign(style4, {
  backgroundColor: "#2e8b57",
  rotation: -90,
  paused: true
}));

$("#tween-1").click(() => tween1.restart());
$("#tween-2").click(() => tween2.restart());
$("#tween-3").click(() => tween3.restart());
$("#tween-4").click(() => tween4.restart());
$("#tween-5").click(() => tween5.restart());
$("#tween-6").click(() => tween6.restart());

// Make content visible
TweenLite.set($("section"), { autoAlpha: 1 });


// ========================================================================
//  CSS EXTENDER
// ========================================================================
function CSSExtender() {

  var camelNames  = {};
  var kebabNames  = {};
  var prefixNames = ["-webkit-", "-moz-", "-ms-"];
  var removeNames = ["transform", "svg"]; 

  createCaseNames();

  return {
    extend: extend
  };

  // Basic functionality to extend CSS styles. Ignores vendor
  // prefixes, shorthand properties, and most transforms
  function extend(config) {

    var style     = {};
    var sources   = _.isArray(config.styles) ? config.styles : [config.styles];
    var target    = getElement(config.target);
    var listNames = getListNames(config.filter);
    var blackList = listNames.blackList;
    var whiteList = listNames.whiteList;

    _.forEach(sources, source => {

      var element = getElement(source);

      element && !whiteList
        ? _.assign(style, getDifference(target, element))
      	: _.assign(style, getStyle(element || source, whiteList));
    });

    return _.omit(style, blackList);
  }

  // Gets the style of a rule or element and filters the result
  // if a whiteList of names is provided
  function getStyle(source, whiteList) {

    var css, style = {};

    if (_.isElement(source)) css = window.getComputedStyle(source);
    if (_.isString(source))  css = CSSRulePlugin.getRule(source);
    if (!(css instanceof CSSStyleDeclaration)) return {};

    var length = whiteList ? whiteList.length : css.length;

    _.times(length, i => {
      var kebab = whiteList ? kebabNames[whiteList[i]] : css[i];
      var camel = camelNames[kebab];
      var value = css.getPropertyValue(kebab);
      if (camel && value) style[camel] = value;
    });

    return style;
  }

  // Converts the filter string into white and black listed names
  function getListNames(filter = "=") {

    var list  = filter.split("="); 
    var names = list[1].split(",");

    return {
      whiteList: list[0] === "+" ? names : null,
      blackList: list[0] === "-" ? names.concat(removeNames) : removeNames
    };
  }

  // Gets the different styles between two elements
  function getDifference(element1, element2) {

    if (!_.isElement(element1) || !_.isElement(element2)) return {};

    TweenLite.set([element1, element2], { y: "+=0" });

    var style  = {};
    var style1 = window.getComputedStyle(element1);
    var style2 = window.getComputedStyle(element2);

    var transform1 = element1._gsTransform;
    var transform2 = element2._gsTransform;

    // Find difference in GSAP transforms
    var transforms = _.omit(transform2, (value, name) => transform1[name] === value);

    // Find difference in CSS values
    _.forOwn(camelNames, (camelCase, name) => {
      var value1 = style1.getPropertyValue(name);
      var value2 = style2.getPropertyValue(name);
      if (value1 !== value2) style[camelCase] = value2;
    });

    return _.assign(style, transforms);
  }

  // Creates a list of CSS properties in camel and kebab case
  function createCaseNames() {

    var style = window.getComputedStyle(document.body);

    _.times(style.length, i => {
      var name = style[i];
      var inList = _.some(prefixNames, prefix => _.includes(name, prefix));
      if (!inList) camelNames[name] = _.camelCase(name);
    });

    kebabNames = _.invert(camelNames);
  }

  function getElement(value) {
    if (!value) return undefined;
    if (_.isElement(value)) return value;
    if (value.jquery) return value[0];
    return undefined;
  }
}
              
            
!
999px

Console