Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support intermittent shaking? #25

Closed
blixt opened this issue Sep 27, 2015 · 2 comments
Closed

Support intermittent shaking? #25

blixt opened this issue Sep 27, 2015 · 2 comments

Comments

@blixt
Copy link

blixt commented Sep 27, 2015

I needed a shake that only occurred for N% of the full animation (so that it would shake for say one second, then not move for three seconds before shaking again), so csshake wasn't a perfect fit for my use case. Maybe support for this could be added?

I ended up writing my own SCSS that wound up being similar to yours, so here it is in case you can use something from it:

@mixin create-shake($name, $x, $y, $angle, $keyframes: 10, $portion: 100%) {
  @keyframes #{$name} {
    $dx: 0px;
    $dy: 0px;
    $rotate: 0deg;

    $offset: 0%;
    $increment: $portion / $keyframes;
    @while $offset < $portion {
      @if $x != 0px { $dx: random($x) - $x / 2; }
      @if $y != 0px { $dy: random($y) - $y / 2; }
      @if $angle != 0deg { $rotate: random($angle) - $angle / 2; }

      #{$offset} {
        transform: translate($dx, $dy) rotate($rotate);
      }

      $offset: $offset + $increment;
    }

    #{if($portion < 100%, ($portion, 100%), 100%)} {
      transform: translate(0px, 0px) rotate(0deg);
    }
  }
}

Example use:

@include create-shake('intermittent', 8px, 8px, 12deg, 10, 30%);

Example output:

@keyframes intermittent {
  0% {
    transform: translate(3px, 1px) rotate(-4deg);
  }
  3% {
    transform: translate(3px, -3px) rotate(3deg);
  }
  6% {
    transform: translate(1px, 3px) rotate(-4deg);
  }
  9% {
    transform: translate(4px, 1px) rotate(0deg);
  }
  12% {
    transform: translate(0px, 2px) rotate(5deg);
  }
  15% {
    transform: translate(-2px, 1px) rotate(0deg);
  }
  18% {
    transform: translate(3px, -1px) rotate(-5deg);
  }
  21% {
    transform: translate(0px, 2px) rotate(6deg);
  }
  24% {
    transform: translate(2px, 0px) rotate(-5deg);
  }
  27% {
    transform: translate(1px, -3px) rotate(-5deg);
  }
  30%, 100% {
    transform: translate(0px, 0px) rotate(0deg);
  }
}
@elrumordelaluz
Copy link
Owner

I'll review it asap @blixt thanks!

elrumordelaluz added a commit that referenced this issue Oct 5, 2015
- Mix everything in one @mixin
- Modifiers classes more semanthic
- Improve code order and declarations
- Add option to only use part of the 100% of keyframes animation (issue #25)
- Allow unitless values for x, y and rotation
- Add option to trigger animation from a parent element (issue #16)
- Having only one @mixing it's possible to export animations separatedly (issue #20)
@elrumordelaluz
Copy link
Owner

hey @blixt first of all, thanks for the idea. I added this feature in the last release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants