概述
動畫欄是使用 HTML 和 CSS 創(chuàng)建的圖形動畫欄。動畫欄的布局是使用 HTML 創(chuàng)建的,欄的樣式是使用 CSS 制作的。普通的條形圖可以正常創(chuàng)建,但我們必須創(chuàng)建帶有動畫的條形圖,因此我們將使用 CSS 過渡動畫屬性來使其具有動畫效果。我們將構(gòu)建一個與音樂動畫條同步器相同的動畫條。
算法
第 1 步 - 在文本編輯器中創(chuàng)建一個 HTML 文件并在其中添加 HTML 樣板。
第 2 步 ? 現(xiàn)在創(chuàng)建一個包含動畫線條的父 div 容器。
<div class="animatedLines"></div>
?第 3 步 ? 在父 div 內(nèi)創(chuàng)建一個 div 子容器。創(chuàng)建至少七個“div”來制作一個好的動畫欄,并將類名作為線條添加到其中。
<div class="lines"></div>
<div class="lines"></div>
<div class="lines"></div>
<div class="lines"></div>
<div class="lines"></div>
<div class="lines"></div>
<div class="lines"></div>
<div class="lines"></div>
?第 4 步 ? 現(xiàn)在創(chuàng)建一個 style.css 文件并將該文件鏈接到 HTML 文檔。
<link rel="stylesheet" href="style.css">
?第 5 步? 在 style.css 文件中設(shè)置 HTML 元素的樣式。
.animatedLines {
display: flex;
justify-content: center;
padding-top: 2rem;
}
.animatedLines .lines:nth-child(1) {
animation-delay: .1s;
background-color: rgb(141, 255, 88);
}
.animatedLines .lines:nth-child(2) {
animation-delay: .2s;
background-color: rgb(127, 253, 69);
}
.animatedLines .lines:nth-child(3) {
animation-delay: .3s;
background-color: rgb(18, 49, 6);
}
.animatedLines .lines:nth-child(4) {
animation-delay: .4s;
background-color: rgb(18, 49, 6);
}
.animatedLines .lines:nth-child(5) {
animation-delay: .3s;
background-color: rgb(18, 49, 6);
}
.animatedLines .lines:nth-child(6) {
animation-delay: .2s;
background-color: rgb(127, 253, 69);
}
.animatedLines .lines:nth-child(7) {
animation-delay: .1s;
background-color: rgb(102, 228, 43);
}
?第 6 步 ? 通過定位子“div”容器的類名來制作這些線條的動畫。
.animatedLines .lines {
list-style: none;
width: 5px;
height: 10px;
margin: 0 4px;
animation: animatedBars .5s infinite alternate;
}
@keyframes animatedBars {
0% {
transform: scaleY(1);
}
25% {
transform: scaleY(1);
}
50% {
transform: scaleY(1);
}
100% {
transform: scaleY(6);
}
}
?
第 7 步? 動畫條已成功創(chuàng)建。
示例
在此示例中,我們創(chuàng)建了一個動畫欄。為此,我們創(chuàng)建了兩個文件:index.html 和 style.css。索引文件包含頁面的布局,style.css 文件包含頁面的樣式部分。
<html>
<head>
<title>animated bars</title>
<link rel="stylesheet" href="style.css">
<style>
.animatedLines {
display: flex;
justify-content: center;
padding-top: 2rem;
}
.animatedLines .lines:nth-child(1) {
animation-delay: .1s;
background-color: rgb(141, 255, 88);
}
.animatedLines .lines:nth-child(2) {
animation-delay: .2s;
background-color: rgb(127, 253, 69);
}
.animatedLines .lines:nth-child(3) {
animation-delay: .3s;
background-color: rgb(18, 49, 6);
}
.animatedLines .lines:nth-child(4) {
animation-delay: .4s;
background-color: rgb(18, 49, 6);
}
.animatedLines .lines:nth-child(5) {
animation-delay: .3s;
background-color: rgb(18, 49, 6);
}
.animatedLines .lines:nth-child(6) {
animation-delay: .2s;
background-color: rgb(127, 253, 69);
}
.animatedLines .lines:nth-child(7) {
animation-delay: .1s;
background-color: rgb(102, 228, 43);
}
.animatedLines .lines {
list-style: none;
width: 5px;
height: 10px;
margin: 0 4px;
animation: animatedBars .5s infinite alternate;
}
@keyframes animatedBars {
0% {
transform: scaleY(1);
}
25% {
transform: scaleY(1);
}
50% {
transform: scaleY(1);
}
100% {
transform: scaleY(6);
}
}
</style>
</head>
<body>
<h1 style="text-align: center;text-decoration: underline;color: green;">tutorialspoint.com</h1>
<div class="animatedLines">
<div class="lines"></div>
<div class="lines"></div>
<div class="lines"></div>
<div class="lines"></div>
<div class="lines"></div>
<div class="lines"></div>
<div class="lines"></div>
<div class="lines"></div>
</div>
</body>
</html>
?
下面給定的圖像顯示了上面示例的輸出,它顯示了一些您可以在瀏覽器上實(shí)時看到的動畫線。當(dāng)用戶將此功能加載到瀏覽器中時,它會顯示一條看起來更有吸引力的動畫線條。文章來源:http://www.zghlxwxcb.cn/news/detail-694030.html
結(jié)論
動畫欄的這一功能可以作為圖形界面在語音合成器中使用。您還可以在許多應(yīng)用程序中看到此組件,例如錄音機(jī)和 dj 節(jié)拍同步器。上面例子中的主要部分是計時,我們設(shè)置了隨著條形尺寸的增加而動畫的計時。文章來源地址http://www.zghlxwxcb.cn/news/detail-694030.html
到了這里,關(guān)于如何使用HTML和CSS創(chuàng)建動畫條形圖?的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!