Skip to content

Instantly share code, notes, and snippets.

@mattdanielbrown
Created June 8, 2024 01:03
Show Gist options
  • Save mattdanielbrown/161cbd13d082d01b25a83d7f5a3d662b to your computer and use it in GitHub Desktop.
Save mattdanielbrown/161cbd13d082d01b25a83d7f5a3d662b to your computer and use it in GitHub Desktop.

Revisions

  1. mattdanielbrown created this gist Jun 8, 2024.
    6 changes: 6 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    8 changes: 8 additions & 0 deletions script.coffeescript
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # applying and removing classes for demo
    # you'll normally be doing interactive stuff like this with this mixin
    toggle = ->
    document.body.classList.toggle "active"
    setTimeout =>
    toggle()
    , 1000
    toggle()
    65 changes: 65 additions & 0 deletions style.scss
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    // actual mixin
    @mixin stagger-delay(

    // delay between staggers, any time
    // unit is valid here
    $delay: 0.1s,

    // children you'd like to count up to
    $total: 1,

    // delay you'd like to start with
    $start: 0s,

    // any additional selectors you'd like
    // to use, in case you're targeting a child
    // of this nth element
    $selector: "",

    // nth kind you're targeting,
    // so: "of-type" or "child"
    $kind: "of-type"

    ){
    $i: 0;
    @while $i < $total {
    &:nth-#{$kind}( #{$total}n+#{$i+1})#{$selector} {
    transition-delay: #{$start+($delay*$i)};
    }
    $i: $i+1;
    }
    }

    // sample usage
    div {
    transition: transform 0.15s ease-in-out;
    transform: translate( 0 , 0% );
    @include stagger-delay( 0.15s , 6 );

    position: relative;
    width: 5vw;
    height: 5vw;
    background-color: red;
    display: inline-block;
    border-radius: 50%;
    margin: 1vw;
    }

    body.active {
    div {
    transform: translate( 0, 150% );
    }
    }

    // some base page styling
    html , body {
    position: absolute;
    text-align: center;
    line-height: 100vh;
    overflow: hidden;
    width: 100%;
    height: 100%;
    font-size: 0;
    left: 0;
    top: 0;
    }
    7 changes: 7 additions & 0 deletions transition-delay-mixin.markdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    Transition Delay Mixin
    ----------------------
    Quickly write delayed transitions.

    A [Pen](https://codepen.io/mattdanielbrown/pen/KKLvMEg) by [Matt Daniel Brown](https://codepen.io/mattdanielbrown) on [CodePen](https://codepen.io).

    [License](https://codepen.io/license/pen/KKLvMEg).