0
0

はじめに

本記事ではHTML、CSSを使用しテキストに横スライドアニメーションをつける方法について記載します。

ゴール

次のような横スライドアニメーションを作成する事を本記事のゴールとする。

slideanimsa.gif

ソース

HTML

htmlファイルを準備します。今回は横からテキストをスライド表示というhtタグのテキストをスライド表示させます。

index.html
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>横スライドアニメーション</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="container">
        <h1 class="animated-text">横からテキストをスライド表示</h1>
    </div>
</body>
</html>

CSS

CSSファイルを準備します。
keyframesで横スライドアニメーション作成します。transformプロパティで画面外から横方向にスライドさせます。

styles.css
body {
  padding: 0;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  background-color: #f0f0f0;
}

.container {
  text-align: center;
}

.animated-text {
  opacity: 0;
  animation: slideIn 1s forwards;
}

@keyframes slideIn {
  from {
    transform: translateX(-100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

実行 & 結果確認

サーバを起動し動作を確認すると下記画像のように、横スライドアニメーションが適用されている事を確認できます。

slideanimsa.gif

0
0
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
0
0