CSSで左上方向への回転アニメーション(rotateInUpLeft)を作成する方法
CSSで「左上を基準に回転する」アニメーション効果(rotateInUpLeft)を作成するには、@keyframesを使って回転の動きを定義し、それを要素に適用します。以下のコードをブラウザで実行すると、実際のアニメーションを確認できます。
サンプルコード
<!DOCTYPE html>
<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 rotateInUpLeft {
0% {
-webkit-transform-origin: left bottom;
-webkit-transform: rotate(0);
opacity: 1;
}
100% {
-webkit-transform-origin: left bottom;
-webkit-transform: rotate(-90deg);
opacity: 0;
}
}
@keyframes rotateInUpLeft {
0% {
transform-origin: left bottom;
transform: rotate(0);
opacity: 1;
}
100% {
transform-origin: left bottom;
transform: rotate(-90deg);
opacity: 0;
}
}
.rotateInUpLeft {
-webkit-animation-name: rotateInUpLeft;
animation-name: rotateInUpLeft;
}
</style>
</head>
<body>
<div id="animated-example" class="animated rotateInUpLeft"></div>
<button onclick="myFunction()">ページを再読み込み</button>
<script>
function myFunction() {
location.reload();
}
</script>
</body>
</html>コードのポイント
- transform-origin: left bottom … 要素の左下を回転の基準点として設定します。これにより、要素が左下を軸にして回転する動きになります。
- @keyframes rotateInUpLeft … アニメーションの開始時点(0%)と終了時点(100%)の状態を定義します。開始時は回転角0度・不透明度1、終了時は-90度回転・不透明度0となります。
- animation-duration: 10s … アニメーションが完了するまでの時間を指定します。この例では10秒かけてゆっくり回転します。
- animation-fill-mode: both … アニメーションの開始前と終了後も、キーフレームで指定したスタイルを維持します。
- -webkit- 接頭辞 … SafariなどWebKit系ブラウザとの互換性を保つために記述しています。最近のブラウザでは標準プロパティのみで動作します。
ページ上の「ページを再読み込み」ボタンをクリックすると、ページが再読み込みされ、アニメーションをもう一度確認できます。回転の速度や角度、基準点を変更すれば、さまざまなバリエーションのアニメーションに応用できます。
-
CSSでrotateOutUpRight(右上へ回転して退場)アニメーションを実装する方法
CSSを使えば、要素が右下を軸として時計回りに90度回転しながら画面から消えていく「rotateOutUpRight(右上へ回転して退場)」アニメーションを簡単に実装できます。この記事では、@keyframesルールとtransform-originプロパティを組み合わせた具体的な実装例を紹介します。 rotateOutUpRightアニメーションの仕組み このアニメーションは、以下のCSSプロパティを組み合わせて実現します。 transform-origin:回転の軸となる基準点を指定します。ここでは「right bottom(右下)」を指定しています。 transform: rotate
-
CSSで左上方向へ回転して消えるアニメーション(rotateOutUpLeft)を作る方法
CSSのrotateOutUpLeftは、要素が左下を軸として反時計回りに回転しながら画面外へ消えていくアニメーション効果です。@keyframesで回転角度と不透明度(opacity)の変化を定義し、animation-nameを使って対象の要素に適用します。 実装例 以下のコードでは、ロゴ画像が10秒かけて左下を基点に-90度回転しながらフェードアウトしていきます。「Reload page」ボタンをクリックするとページが再読み込みされ、アニメーションを何度でも確認できます。 <html> <head> <style> .animated { bac