CSSでrotateInUpRight(右上へ回転しながら登場)アニメーションを実装する方法
CSSの@keyframesとtransformプロパティを組み合わせることで、要素が右下を支点に回転しながらフェードインしてくる「rotateInUpRight」アニメーションを簡単に実装できます。
rotateInUpRightアニメーションの仕組み
このアニメーションでは、以下のポイントを押さえています。
- transform-origin: right bottom … 要素の右下を回転の中心(支点)に設定します。
- transform: rotate(-90deg) … 開始時点では要素を-90度(左に倒れた状態)に傾けます。
- opacity … 開始時に0(透明)、終了時に1(不透明)へ変化させ、フェードイン効果を加えます。
実装例
次のコードをブラウザで実行すると、ロゴ画像が右上方向へ回転しながら表示されるアニメーションを確認できます。「Reload page」ボタンをクリックすると、ページが再読み込みされてアニメーションを再度再生できます。
<html>
<head>
<style>
.animated {
background-image: url(/css/images/logo.png);
background-repeat: no-repeat;
background-position: left top;
padding-top: 95px;
margin-bottom: 60px;
-webkit-animation-duration: 10s;
animation-duration: 10s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
@-webkit-keyframes rotateInUpRight {
0% {
-webkit-transform-origin: right bottom;
-webkit-transform: rotate(-90deg);
opacity: 0;
}
100% {
-webkit-transform-origin: right bottom;
-webkit-transform: rotate(0);
opacity: 1;
}
}
@keyframes rotateInUpRight {
0% {
transform-origin: right bottom;
transform: rotate(-90deg);
opacity: 0;
}
100% {
transform-origin: right bottom;
transform: rotate(0);
opacity: 1;
}
}
.rotateInUpRight {
-webkit-animation-name: rotateInUpRight;
animation-name: rotateInUpRight;
}
</style>
</head>
<body>
<div id = "animated-example" class = "animated rotateInUpRight"></div>
<button onclick = "myFunction()">Reload page</button>
<script>
function myFunction() {
location.reload();
}
</script>
</body>
</html>コードのポイント解説
このサンプルでは、animation-duration: 10sによって10秒かけてゆっくりとアニメーションが再生されます。より軽快な印象にしたい場合は、値を1sや2sなど短く変更してみてください。また、animation-fill-mode: bothを指定することで、アニメーション開始前から終了後までスタイルが適切に保持されます。
なお、-webkit-プレフィックスは旧バージョンのSafariやChrome向けのもので、現在のモダンブラウザでは標準の@keyframesだけで動作しますが、幅広い環境への互換性を持たせるために両方記述しておくのが安全です。
-
CSSで左上方向へ回転して消えるアニメーション(rotateOutUpLeft)を作る方法
CSSのrotateOutUpLeftは、要素が左下を軸として反時計回りに回転しながら画面外へ消えていくアニメーション効果です。@keyframesで回転角度と不透明度(opacity)の変化を定義し、animation-nameを使って対象の要素に適用します。 実装例 以下のコードでは、ロゴ画像が10秒かけて左下を基点に-90度回転しながらフェードアウトしていきます。「Reload page」ボタンをクリックするとページが再読み込みされ、アニメーションを何度でも確認できます。 <html> <head> <style> .animated { bac
-
CSSで実現する「右下を支点に回転しながら消える」アニメーション効果の作り方
CSSのアニメーションを使えば、要素を右下(right bottom)を支点として回転させながらフェードアウトさせる演出が簡単に実装できます。この効果は一般的に rotateOutDownRight と呼ばれ、要素が画面から消える際の退場アニメーションとしてよく活用されます。rotateOutDownRightアニメーションの仕組みこのアニメーションでは、以下のCSSプロパティが重要な役割を果たします。transform-origin: right bottom; … 回転の基準点を要素の右下に設定します。transform: rotate(-90deg); … 要素を反時計回りに90度回転さ