123

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              
<div class="contain">
  <h1>@include transform-tags();</h1>
  <ul class="transform-tags process1">
    <li class="middle"><span class="tag"></span><span class="tag"></span><span class="tag"></span><span class="tag"></span><span class="tag"></span><span class="tag"></span><span class="tag"></span><span class="tag"></span><span class="tag"></span><span class="tag"></span>
    </li>
  </ul>
  <h3>Use this <code>@mixin</code> to generate a <span>progressive element gradient</span>.</h3>
  <p><strong>Progressive element gradient</strong> - When a set of elements <code>background-color</code>'s form a gradient from <span class="color-a">Color A</span> to <span class="color-b">Color B</span>.</p>
</div>
<div class="contain">
  <p>Using the built in SASS function <code>mix</code>, this <code>@mixin</code> takes 3 parameters to create a gradient effect across a number of elements.</p>
  <p>The <code>mix</code> function works as follows:</p>
  <ol>
    <li>Three parameters are passed: $color1, $color2, $weight</li>
    <li>$weight determines how much of $color1 will be returned with $color2</li>
  </ol>
  <p>A simple example would be if <code>$color1: white</code>, <code>$color2: black</code>, and <code>$weight: 80%</code>, a light grey would be returned.</p>
  <ul class="grey-example">
    <li class="start">$color1</li>
    <li class="middle">mix($color1, $color2, 80%)</li>
    <li class="end">$color2</li>
  </ul>
</div>
<div class="contain">
  <h2>How the <code>@mixin</code> works.</h2>
  <p>Three parameters are accepted: <code>$color1</code>, <code>$color2</code>, and <code>$tags</code>.</p>
  <p><code>$color1</code> and <code>$color2</code> represent the colors as they are passed to the <code>mix</code> function.</p>
  <p><code>$tags</code> represents how many elements should make up the progressive gradient.</p>
  <p>With all the information available, the <code>@mixin</code> will create pseudo classes and calculate the proper <code>$weight</code> to pass to the <code>mix</code> function for each element.</p>
  <h4>In the first example, below, see the colors with what <code>$weight</code> has been passed to the <code>mix</code> function.</h4>
</div>
<div class="contain">
  <ul class="transform-tags process1">
    <li class="start"></li>
    <li class="middle"><span class="tag">Tag 1</span><span class="tag">Tag 2</span><span class="tag">Tag 3</span><span class="tag">Tag 4</span><span class="tag">Tag 5</span><span class="tag">Tag 6</span><span class="tag">Tag 7</span>
    </li>
    <li class="end"></li>
  </ul>
</div>
<div class="contain">
  <ul class="transform-tags process2">
    <li class="start"></li>
    <li class="middle"><span class="tag">Tag 1</span><span class="tag">Tag 2</span><span class="tag">Tag 3</span><span class="tag">Tag 4</span><span class="tag">Tag 5</span><span class="tag">Tag 6</span><span class="tag">Tag 7</span><span class="tag">Tag 8</span><span class="tag">Tag 9</span>
    </li>
    <li class="end"></li>
  </ul>
</div>
<div class="contain">
  <ul class="transform-tags process3">
    <li class="start"></li>
    <li class="middle"><span class="tag">Tag 1</span><span class="tag">Tag 2</span><span class="tag">Tag 3</span><span class="tag">Tag 4</span><span class="tag">Tag 5</span>
    </li>
    <li class="end"></li>
  </ul>
</div>
            
          
!
            
              $base: #94c6fd;

$max-tags: 10;

$tag1-start: #66ce5b;
$tag1-end: #a561cb;

$tag2-start: #ffb81c;
$tag2-end: #c6538c;

$tag3-start: $base;
$tag3-end: #d75e5e;

@mixin transform-tags ( $color1, $color2, $tags: 5 ) {
  $tag: 1;
  @while $tag <= $tags {
    $weight: 100% - ((90%/$tags) * $tag);
    &:nth-child(#{$tag}) {
      background-color: mix($color1, $color2, $weight);
    }
    $tag: $tag + 1;
  }
}

@mixin transform-tags-with-cap ( $color1, $color2, $tags: 5 ) {
  $tag: 1;
  @while $tag <= $tags {
    $weight: 100% - ((90%/$tags) * $tag);
    &:nth-child(#{$tag}) {
      background-color: mix($color1, $color2, $weight);
      &:before {
        content: '#{$weight}';
      }
    }
    $tag: $tag + 1;
  }
}

:root {
  background: $base;
  box-sizing: border-box;
  padding: 3em;
  @media all and ( max-width: 800px ) {
    padding: 1em;
  }
  *, &:before, &:after {
    box-sizing: inherit;
    -webkit-font-smoothing: antialiased !important;
  }
  .contain {
    background: white;
    box-shadow: 0 2px 2px darken($base, 15%);
    color: #111;
    font-size: 1.3em;
    max-width: 1000px; width: 100%;
    margin: 0 auto; padding: 3em;
    text-shadow: 1px 1px 1px rgba(black, 0.004);
    position: relative;
    + .contain {
      margin-top: 3em;
    }
    a {
      color: darken($base, 10%);
    }
  }
}

.transform-tags {
  cursor: pointer;
  list-style: none;
  margin: 0; padding: 0;
  li {
    height: 75px; width: 100%;
    &.middle {
      overflow: hidden;
      padding: 20px 0;
      span {
        display: inline-block;
        height: 35px;
        line-height: 35px;
        padding: 0 10px;
      }
    }
    .tag {
      color: #eee;
      position: relative;
      width: 10%;
      &:before {
        color: #111;
        font-size: 12px;
        height:20px; line-height: 20px;
        position: absolute;
        top: 100%;
      }
    }
  }
  
  &.process1 {
    $tag: 1;
    @while $tag <= $max-tags {
      &.color-#{$tag}-tags {
        .start {
          background: $tag1-start;
        }
        .end {
          background: $tag1-end;
        }
        .tag {
          background-color: $tag1-start;
          @include transform-tags-with-cap($tag1-start, $tag1-end, $tag);
        }
      }
      $tag: $tag + 1;
    }
  }

  &.process2 {
    $tag: 1;
    @while $tag <= $max-tags {
      &.color-#{$tag}-tags {
        .start {
          background: $tag2-start;
        }
        .end {
          background: $tag2-end;
        }
        .tag {
          background-color: $tag2-start;
          @include transform-tags($tag2-start, $tag2-end, $tag);
        }
      }
      $tag: $tag + 1;
    }
  }

  &.process3 {
    $tag: 1;
    @while $tag <= $max-tags {
      &.color-#{$tag}-tags {
        .start {
          background: $tag3-start;
        }
        .end {
          background: $tag3-end;
        }
        .tag {
          background-color: $tag3-start;
          @include transform-tags($tag3-start, $tag3-end, $tag);
        }
      }
      $tag: $tag + 1;
    }
  }
}

code {
  background: lighten($base, 15%);
  padding: 0 3px;
}

h1, h3 {
  text-align: center;
  span {
    color: darken($base, 30%);
  }
}

.color-a { color: $tag1-start; }
.color-b { color: $tag1-end; }

.grey-example {
  list-style: none;
  margin: 0 0 25px; padding: 0;
  overflow: auto;
  width: 100%;
  li {
    border: 1px solid black;
    float: left;
    height: 100px; width: calc((100% - (2 * 15px))/3);
    line-height: 100px;
    margin: 0; padding: 0;
    text-align: center;
    + li {
      margin-left: 15px;
    }
  }
  .start { background: white; }
  .middle { background: mix(white, black, 80%); white-space: nowrap; }
  .end { background: black; color: white; }
}
            
          
!
            
              var showAnimation = true;

var animTags = function () {
  
  if ( ! showAnimation ) return false;
  
  var to = $(this).offset().left,
      del = 100,
      startColor = $(this).parent().prev('li').css('background-color'),
      endColor = $(this).data('color');

  $(this).css({top: '-200%', backgroundColor: startColor});

  $(this).delay(del * ($(this).index()/2)).animate({
    top: 0
  }, 500, function () {
    $(this).delay(del * ($(this).index()/4)).animate({
      backgroundColor: endColor
    }, 'slow');
  });
  
};

$('.transform-tags').each(function () {
  
  var _tags = $('.tag', this),
      _tagLen = _tags.length;

  $(this).addClass('color-' + _tagLen + '-tags');
  
  _tags.each(function () {
    $(this).attr('data-color', $(this).css('background-color'));
  } );

  _tags.each(animTags);
  
} ).on('click', function () {
  
  $('.tag', this).each(animTags);
  
} );
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console