CSS

グリッチエフェクトをCSSだけで付ける方法!ビビビッっとアニメーション実装!

今回は、web制作で使用できるエフェクトをCSSだけで実装するよ!
まるでTVが壊れたときみたいなビビビッとするあの感じをCSSだけでだけで作ってみよう!
じゃあ早速始めるよ!

グリッチエフェクトをCSSだけで付ける方法

では早速実装していくよ。

まずはHTML。

<p class="glitch-effect" data-text="ビビビ!!">ビビビ!!</p> 

 

シラツキ
シラツキ
表示させたいテキストとHTML5のdata属性に同じテキストを入れるのがポイント!

 

続いて、Scssを書いていくよ。
CSSで書くのはしんどいのでScssで書いたけど、念の為CSSも下に書いてあるのでCSSで書いている場合は下のコードをコピーしてね!

// アニメーション設定
@keyframes glitch {
  $steps: 20;
  @for $i from 0 through $steps {
    #{percentage($i*(1/$steps))} {
      clip: rect(random(100) + px, 9999px, random(100) + px, 0);
    }
  }
}
 
@keyframes glitch-2 {
  $steps: 20;
  @for $i from 0 through $steps {
    #{percentage($i*(1/$steps))} {
      clip: rect(random(100) + px, 9999px, random(100) + px, 0);
    }
  }
}
 
.glitch-effect {
  color: white;
  font-size: 80px;
  position: relative;
  width: 400px;
  margin: 0 auto;
}
 
.glitch-effect:after {
  content: attr(data-text);
  position: absolute;
  left: 2px;
  text-shadow: -1px 0 red;
  top: 0;
  color: white;
  background: black;
  overflow: hidden;
  clip: rect(0, 900px, 0, 0);
  animation: glitch 2s infinite linear alternate-reverse;
}
 
.glitch-effect:before {
  content: attr(data-text);
  position: absolute;
  left: -2px;
  text-shadow: 1px 0 blue;
  top: 0;
  color: white;
  background: black;
  overflow: hidden;
  clip: rect(0, 900px, 0, 0);
  animation: glitch-2 3s infinite linear alternate-reverse;
}

 

 

CSSはこちら。

シラツキ
シラツキ
めっちゃ長い・・・!!
body {
  background: black;
}
 
@-webkit-keyframes glitch {
  0% {
    clip: rect(17px, 9999px, 62px, 0);
  }
  5% {
    clip: rect(43px, 9999px, 46px, 0);
  }
  10% {
    clip: rect(87px, 9999px, 1px, 0);
  }
  15% {
    clip: rect(11px, 9999px, 13px, 0);
  }
  20% {
    clip: rect(9px, 9999px, 87px, 0);
  }
  25% {
    clip: rect(8px, 9999px, 66px, 0);
  }
  30% {
    clip: rect(87px, 9999px, 1px, 0);
  }
  35% {
    clip: rect(3px, 9999px, 37px, 0);
  }
  40% {
    clip: rect(54px, 9999px, 8px, 0);
  }
  45% {
    clip: rect(35px, 9999px, 49px, 0);
  }
  50% {
    clip: rect(38px, 9999px, 94px, 0);
  }
  55% {
    clip: rect(66px, 9999px, 56px, 0);
  }
  60% {
    clip: rect(10px, 9999px, 70px, 0);
  }
  65% {
    clip: rect(100px, 9999px, 46px, 0);
  }
  70% {
    clip: rect(24px, 9999px, 70px, 0);
  }
  75% {
    clip: rect(47px, 9999px, 68px, 0);
  }
  80% {
    clip: rect(67px, 9999px, 97px, 0);
  }
  85% {
    clip: rect(5px, 9999px, 13px, 0);
  }
  90% {
    clip: rect(84px, 9999px, 20px, 0);
  }
  95% {
    clip: rect(53px, 9999px, 39px, 0);
  }
  100% {
    clip: rect(57px, 9999px, 79px, 0);
  }
}
 
@keyframes glitch {
  0% {
    clip: rect(17px, 9999px, 62px, 0);
  }
  5% {
    clip: rect(43px, 9999px, 46px, 0);
  }
  10% {
    clip: rect(87px, 9999px, 1px, 0);
  }
  15% {
    clip: rect(11px, 9999px, 13px, 0);
  }
  20% {
    clip: rect(9px, 9999px, 87px, 0);
  }
  25% {
    clip: rect(8px, 9999px, 66px, 0);
  }
  30% {
    clip: rect(87px, 9999px, 1px, 0);
  }
  35% {
    clip: rect(3px, 9999px, 37px, 0);
  }
  40% {
    clip: rect(54px, 9999px, 8px, 0);
  }
  45% {
    clip: rect(35px, 9999px, 49px, 0);
  }
  50% {
    clip: rect(38px, 9999px, 94px, 0);
  }
  55% {
    clip: rect(66px, 9999px, 56px, 0);
  }
  60% {
    clip: rect(10px, 9999px, 70px, 0);
  }
  65% {
    clip: rect(100px, 9999px, 46px, 0);
  }
  70% {
    clip: rect(24px, 9999px, 70px, 0);
  }
  75% {
    clip: rect(47px, 9999px, 68px, 0);
  }
  80% {
    clip: rect(67px, 9999px, 97px, 0);
  }
  85% {
    clip: rect(5px, 9999px, 13px, 0);
  }
  90% {
    clip: rect(84px, 9999px, 20px, 0);
  }
  95% {
    clip: rect(53px, 9999px, 39px, 0);
  }
  100% {
    clip: rect(57px, 9999px, 79px, 0);
  }
}
 
@-webkit-keyframes glitch-2 {
  0% {
    clip: rect(19px, 9999px, 94px, 0);
  }
  5% {
    clip: rect(81px, 9999px, 97px, 0);
  }
  10% {
    clip: rect(58px, 9999px, 48px, 0);
  }
  15% {
    clip: rect(16px, 9999px, 47px, 0);
  }
  20% {
    clip: rect(54px, 9999px, 27px, 0);
  }
  25% {
    clip: rect(93px, 9999px, 1px, 0);
  }
  30% {
    clip: rect(55px, 9999px, 19px, 0);
  }
  35% {
    clip: rect(34px, 9999px, 38px, 0);
  }
  40% {
    clip: rect(82px, 9999px, 79px, 0);
  }
  45% {
    clip: rect(45px, 9999px, 44px, 0);
  }
  50% {
    clip: rect(67px, 9999px, 59px, 0);
  }
  55% {
    clip: rect(83px, 9999px, 6px, 0);
  }
  60% {
    clip: rect(95px, 9999px, 70px, 0);
  }
  65% {
    clip: rect(74px, 9999px, 12px, 0);
  }
  70% {
    clip: rect(21px, 9999px, 2px, 0);
  }
  75% {
    clip: rect(1px, 9999px, 23px, 0);
  }
  80% {
    clip: rect(11px, 9999px, 91px, 0);
  }
  85% {
    clip: rect(81px, 9999px, 10px, 0);
  }
  90% {
    clip: rect(22px, 9999px, 98px, 0);
  }
  95% {
    clip: rect(68px, 9999px, 59px, 0);
  }
  100% {
    clip: rect(79px, 9999px, 12px, 0);
  }
}
 
@keyframes glitch-2 {
  0% {
    clip: rect(19px, 9999px, 94px, 0);
  }
  5% {
    clip: rect(81px, 9999px, 97px, 0);
  }
  10% {
    clip: rect(58px, 9999px, 48px, 0);
  }
  15% {
    clip: rect(16px, 9999px, 47px, 0);
  }
  20% {
    clip: rect(54px, 9999px, 27px, 0);
  }
  25% {
    clip: rect(93px, 9999px, 1px, 0);
  }
  30% {
    clip: rect(55px, 9999px, 19px, 0);
  }
  35% {
    clip: rect(34px, 9999px, 38px, 0);
  }
  40% {
    clip: rect(82px, 9999px, 79px, 0);
  }
  45% {
    clip: rect(45px, 9999px, 44px, 0);
  }
  50% {
    clip: rect(67px, 9999px, 59px, 0);
  }
  55% {
    clip: rect(83px, 9999px, 6px, 0);
  }
  60% {
    clip: rect(95px, 9999px, 70px, 0);
  }
  65% {
    clip: rect(74px, 9999px, 12px, 0);
  }
  70% {
    clip: rect(21px, 9999px, 2px, 0);
  }
  75% {
    clip: rect(1px, 9999px, 23px, 0);
  }
  80% {
    clip: rect(11px, 9999px, 91px, 0);
  }
  85% {
    clip: rect(81px, 9999px, 10px, 0);
  }
  90% {
    clip: rect(22px, 9999px, 98px, 0);
  }
  95% {
    clip: rect(68px, 9999px, 59px, 0);
  }
  100% {
    clip: rect(79px, 9999px, 12px, 0);
  }
}
 
.glitch-effect {
  color: white;
  font-size: 80px;
  position: relative;
  width: 400px;
  margin: 0 auto;
}
 
.glitch-effect:after {
  content: attr(data-text);
  position: absolute;
  left: 2px;
  text-shadow: -1px 0 red;
  top: 0;
  color: white;
  background: black;
  overflow: hidden;
  clip: rect(0, 900px, 0, 0);
  animation: glitch 2s infinite linear alternate-reverse;
}
 
.glitch-effect:before {
  content: attr(data-text);
  position: absolute;
  left: -2px;
  text-shadow: 1px 0 blue;
  top: 0;
  color: white;
  background: black;
  overflow: hidden;
  clip: rect(0, 900px, 0, 0);
  animation: glitch-2 3s infinite linear alternate-reverse;
}

 

こんな感じ!
かっこよく動くサイトを作ってみてね♪

お仕事・ご依頼募集中!!

イラスト制作、webサイト制作、商品のご紹介など様々なお仕事を募集しております! 下記リンクよりお気軽にご連絡ください!

お仕事・ご依頼について