ホームページ >ウェブフロントエンド >ブートストラップのチュートリアル >BootstrapのProgress Barコンポーネントを使用して、タスクの完了を示すにはどうすればよいですか?
BootstrapのProgress Barコンポーネントを使用してタスクの完了を示すには、次の手順に従う必要があります。
HTML構造:Basic Progress Barに次のHTML構造を使用します。
<code class="html"><div class="progress"> <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div> </div></code>
進行状況を設定します。進行状況を設定するには、 .progress-bar
のwidth
を調整し、 aria-valuenow
属性を更新する必要があります。たとえば、タスクが50%完了した場合、HTMLは次のようになります。
<code class="html"><div class="progress"> <div class="progress-bar" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div> </div></code>
オプションのラベル:ラベルを追加して、進行状況バー内のパーセンテージを表示することもできます。
<code class="html"><div class="progress"> <div class="progress-bar" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">50%</div> </div></code>
これらの手順に従うことにより、BootstrapのProgress Barを使用して、タスクの完了ステータスを視覚的に示すことができます。
BootstrapのProgress Barコンポーネントは、さまざまなニーズに合わせていくつかのカスタマイズオプションを提供します。
色: .bg-success
、 .bg-info
、 .bg-warning
、 .bg-danger
などのコンテキストクラスを追加することで、進行状況バーの色を変更できます。
<code class="html"><div class="progress"> <div class="progress-bar bg-success" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div> </div></code>
ストライプ: .progress-bar-striped
クラスを含めることにより、Progress Barにストライプ効果を追加します。
<code class="html"><div class="progress"> <div class="progress-bar progress-bar-striped" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div> </div></code>
アニメーションストライプ:ストライプをアニメーション化するには、 .progress-bar-animated
.progress-bar-striped
アニメーションクラスを追加します。
<code class="html"><div class="progress"> <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div> </div></code>
高さ: .progress
コンテナのheight
プロパティを変更することにより、進行状況バーの高さを調整できます。
<code class="html"><div class="progress" style="height: 20px;"> <div class="progress-bar" role="progressbar" style="width: 50%; height: 20px;" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div> </div></code>
複数のバー:単一の.progress
コンテナ内に複数の進行状況バーを表示して、複数の進行状況を同時に表すことができます。
<code class="html"><div class="progress"> <div class="progress-bar" role="progressbar" style="width: 30%" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100">30%</div> <div class="progress-bar bg-success" role="progressbar" style="width: 20%" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100">20%</div> </div></code>
これらのカスタマイズオプションを使用すると、BootstrapのProgress Barの外観と機能を調整して、特定の要件に合わせて調整できます。
BootstrapのProgress Barをアニメーション化してリアルタイムの更新を表示するには、JavaScriptを使用して.progress-bar
のwidth
動的に更新できます。これを行う方法の例は次のとおりです。
HTML構造:基本的な進行状況バー構造から始めます。
<code class="html"><div class="progress" id="myProgress"> <div class="progress-bar" role="progressbar" id="myBar" style="width: 0%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div> </div></code>
JavaScriptコード:JavaScriptを使用して、進行状況バーをアニメーション化します。次の例は、0%から100%へのスムーズな遷移を示しています。
<code class="javascript">let progressBar = document.getElementById("myBar"); let width = 0; let interval = setInterval(frame, 50); function frame() { if (width >= 100) { clearInterval(interval); } else { width ; progressBar.style.width = width "%"; progressBar.setAttribute("aria-valuenow", width); progressBar.innerHTML = width "%"; } }</code>
CSSの遷移:アニメーションをスムーズにするために、 .progress-bar
にCSSトランジションを追加できます。
<code class="css">.progress-bar { transition: width 0.5s ease-in-out; }</code>
このJavaScriptコードは、50ミリ秒ごとに進行状況バーの幅を段階的に増加させ、リアルタイムの更新が表示されます。特定のニーズに合わせて、 interval
とwidth
増分を調整できます。
はい、BootstrapのProgress Barを使用して、単一の.progress
コンテナ内に複数の.progress-bar
要素を配置することにより、複数の進行状況ステータスを同時に表示できます。これがそれを行う方法です:
HTML構造: .progress
コンテナを作成し、その内部に複数の.progress-bar
要素を追加します。
<code class="html"><div class="progress"> <div class="progress-bar bg-success" role="progressbar" style="width: 30%" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100">30%</div> <div class="progress-bar bg-info" role="progressbar" style="width: 20%" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100">20%</div> <div class="progress-bar bg-warning" role="progressbar" style="width: 10%" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100">10%</div> </div></code>
.bg-success
、 .bg-info
、 .bg-warning
などのコンテキストクラスを使用して、さまざまな色で各.progress-bar
カスタマイズして、さまざまなタスクまたはステータスを表します。複数の.progress-bar
要素を使用することにより、単一の進行状況バー内の複数のタスクの完了ステータスを視覚的に表すことができ、複雑な進行状況情報を表示するための多用途ツールになります。
以上がBootstrapのProgress Barコンポーネントを使用して、タスクの完了を示すにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。