LoginSignup
0
0

More than 5 years have passed since last update.

animation使ってみました

Posted at

cssのアニメーションを使ったことがなかったので,使ってみました.
(シンプルなものだと意外と簡単だった!!凝りだすとはまりそうだけど...)
上の緑の四角にマウスオーバー⇒赤緑青の四角が動くようにしてあります.
(他の要素をcssのみで動かすっていうがと意外に難しかった)

aaaa.gif

sample.html
<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="./sample.css">
</head>

<body>
    <div class="test1"></div>
    <div class="test"></div>
</body>

</html>
sample.css
.test {
    width: 30px;
    height: 30px;
    margin: 0 auto;
    margin-top: 400px;
    box-shadow: 50px 0px red, 100px 0px green, 150px 0px blue;
}

.test1 {
    width: 200px;
    height: 76px;
    margin: 0 auto;
    background-color: green;
}

.test1:hover+.test {
    animation: ue 1s forwards, shita 1s 1s forwards;
    animation-timing-function: ease-out;
}

@keyframes ue {
    from {
        margin-top: 400px;
    }
    to {
        margin-top: 100px;
    }
}

@keyframes shita {
    from {
        margin-top: 100px;
    }
    to {
        margin-top: 400px;
    }
}


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