簡単に言うと
最近ページを作成するときに、下から上にポップアップ表示されるプロンプト ボックスが必要になります。
しばらく瞑想した後、それは現実になりました。
実装のアイデアを記録します。
実装のアイデア
実装手順は次のとおりです。
- スタイルを書きます。
ホームページには、コンテンツを運ぶためのコンテナ (ボックス) が必要です。外層は梱包箱で覆われています(位置決めとスタイル定義用)。
- ポップアップエフェクトロジックをトリガーします。
ここでは、マウスを上に移動してコンテンツを表示し、ポップアップ効果をトリガーします。実際のアプリケーションでは、他のトリガー方法が使用される場合があります。 - ポップアップ効果を実現。
CSS トランジションとトランスフォームを使用して実現します - コンポーネントにパッケージ化されています。
関連する属性または主要な操作を提案し、構成可能なコンポーネントにカプセル化できます。
スタイルとトリガーロジックを記述する
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.wrapper {
position: relative;
min-width: 10px;
min-height: 10px;
width: 400px;
height: 200px;
min-height: 10px;
margin-left: calc(50% - 100px);
margin-top: 100px;
border-radius: 50px 20px 50px 20px;
background-color: skyblue;
}
.box {
position: absolute;
top: 0;
left: 0;
display: block;
width: 100%;
height: 100%;
cursor: pointer;
border-radius: inherit;
background-color: #666;
}
.wrapper:hover .box {
transform: translate(0, 0);
}
</style>
</head>
<body>
<div class="wrapper">
<div class="box">文字显示区域巴拉巴拉。。。</div>
</div>
</body>
</html>
マウスを上に移動すると、ポップアップ効果がトリガーされます。
ポップアップ効果をデザインする
ポップアップ効果はCSSの遷移と変形で実現します。
transform は、表示コンテンツのボックス (ボックス) を変換します。
トランジション トランジションをアニメーション化します。
たとえば、
デフォルトでは、ボックスを下に 100% 移動し、右に 100% 移動します。
マウスが中に入ると元の位置に戻ります。
.box{
transform: translate(100%, 100%);
transition: 0.5s ease all;
}
.wrapper:hover .box {
transform: translate(0, 0);
}
この効果は、コンテンツ領域のポップアップ効果を右下から右上に表示することです。
ラッパーは背景色を削除し、 overflow: hidden ; 効果を追加します。
コンポーネントにパッケージ化
トリガー モード、変換ポップアップ効果、トランジション アニメーション スタイル、継続時間などの主要な属性を提案し、構成可能なコンポーネントにパッケージ化できます。
急いで試してみてください。
エピローグ
完全なコード。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.wrapper {
position: relative;
min-width: 10px;
min-height: 10px;
width: 400px;
height: 200px;
min-height: 10px;
margin-left: calc(50% - 100px);
margin-top: 100px;
border-radius: 50px 20px 50px 20px;
/* background-color: skyblue; */
overflow: hidden;
}
.box {
position: absolute;
top: 0;
left: 0;
display: block;
width: 100%;
height: 100%;
transform: translate(100%, 100%);
transition: 0.5s ease all;
cursor: pointer;
border-radius: inherit;
background-color: #666;
}
.wrapper:hover .box {
transform: translate(0, 0);
}
</style>
</head>
<body>
<div class="wrapper">
<div class="box">文字显示区域巴拉巴拉。。。</div>
</div>
</body>
</html>