1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CSS animation で遊び倒す - Curtain Opening Effect 2-

Last updated at Posted at 2019-02-13

CSS animation day23 となりました。

昨日のカーテンの出来に納得がいかなかったため、別のアニメーションで表現します。

1. 完成版

ダウンロード (58).gif

See the Pen Curtain Open by hiroya iizuka (@hiroyaiizuka) on CodePen.

2. 参考文献

CSS Curtain Effects

3. 分解してみる

❶.
まず、スクリーンの枠を作ります。

index.html
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="UTF-8" />
    <link rel="stylesheet" href="css/styles.css" />
  </head>
  <body>
    <div class="theatre">
      <div class="curtain-left"></div>
      <div class="curtain-right"></div>
    </div>
  </body>
</html>
styles.css
body {
  margin: 0px;
  padding: 0px;
  background: #fff;
  display: flex;
  justify-content: center;
  overflow: hidden;
}

.theatre {
  border: inset #000 10px;
  margin: 50vh auto;
  transform: translateY(-50%);
  height: 300px;
  width: 80%;
}
スクリーンショット 2019-02-13 9.50.28.png

❷.
カーテンを入れる

styles.css
.theatre {
  border: inset #000 10px;
  margin: 50vh auto;
  transform: translateY(-50%);
  height: 300px;
  width: 80%;
  position: relative;
  overflow: hidden;
}

.curtain-left,
.curtain-right {
  position: absolute;
  top: -30px;
  bottom: -30px;
  width: 61%;
  background-color: rgb(255, 0, 10);
}
スクリーンショット 2019-02-13 10.03.26.png

なお、theatre にoverflow: hidden をつけることで、赤いカーテン(仮)が枠を超えずに、黒いborder内におさまります。


❸.
カーテンを左右別に配置する。

styles.css
.curtain-left {
  left: -10%;
}

.curtain-right {
  right: -10%;
}
スクリーンショット 2019-02-13 10.09.31.png

ぴったりおさまりました。
続いて、カーテンの模様を、linear-gradient プロパティで、表現します。

styles.css

.curtain-left,
.curtain-right {
  position: absolute;
  top: -30px;
  bottom: -30px;
  width: 61%;
  background-color: rgb(255, 0, 10);
  background-image: linear-gradient(
    90deg,
    rgba(204, 0, 10, 1) 30%,
    transparent 50%,
    rgba(204, 0, 10, 1) 80%,
    transparent 100%
  );
  background-size: 90px;
}
スクリーンショット 2019-02-13 10.37.44.png

linear-gradient: 90deg でグラデーションを縦線にし、濃い目の赤で影を表現しております。この辺は、自由にデザインできるところでしょう。

グラデーションの指定サイズを決めるために、background-sizeを使用しております。詳しくは こちら にわかりやすくのっております。


❹.
では、hover してアニメーションを発動させましょう。

styles.css
.theatre:hover .curtain-left {
  transform: translateX(-100%);
  transition: all 3s ease;
}

.theatre:hover .curtain-right {
  transform: translateX(100%);
  transition: all 3s ease;
}

ダウンロード (52).gif

昨日と全く同じアニメーションをつけましたが、なんかまだ物足りません。左のカーテンに、rotate をつけてみましょう。

ダウンロード (53).gif

少しいい感じになりました。
カーテンのtop が足りないたので、-300px にします。

styles.css
.curtain-left,
.curtain-right {
  position: absolute;
  top: -300px;
  bottom: -30px;

そして、アニメーションがbottom を中心に動くようにします。
わかりづらいですが、左が修正後、右が修正前です。

styles.css
.theatre:hover .curtain-left {
  transform: translateX(-100%) rotate(15deg);
  transition: all 3s ease;
  transform-origin: 50% bottom;
}

.theatre:hover .curtain-right {
  transform: translateX(100%) rotate(-15deg);
  transition: all 3s ease;
}

ダウンロード (54).gif

いい感じです!
ただ、まだ、カーテンの内側の動きが硬いですね。
ここは、filter でshadow をつけてみます。
左が修正後、右が修正前です。

styles.css
.curtain-left {
  left: -10%;
  filter: drop-shadow(1px 6px 6px black);
}

.curtain-right {
  right: -10%;
}

ダウンロード (55).gif

いいですね!
そろそろ仕上げます。劇場のカーテンをイメージし、box-shadow inset で、カーテン全体に影をつけましょう。

styles.css
.curtain-left {
  left: -10%;
  filter: drop-shadow(1px 6px 6px black);
  box-shadow: -2px 0px 6px rgba(255, 255, 255, 0.4) inset,
    0px 320px 40px rgba(0, 0, 0, 0.5) inset;
}

.curtain-right {
  right: -10%;
  filter: drop-shadow(1px 6px 6px black);
  box-shadow: 2px 0px 6px rgba(255, 255, 255, 0.4) inset,
    -0px 320px 40px rgba(0, 0, 0, 0.5) inset;
}

ダウンロード (58).gif

完成しました!
昨日よりはいい出来になりましたが、もっと丸まったアニメーションを取り入れたりまだまだ改良の余地はありそうです。

それでは、また明日!

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?