創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!

這篇文章將為大家詳細(xì)講解有關(guān)css3實(shí)現(xiàn)進(jìn)度條動態(tài)效果的方法,文章內(nèi)容質(zhì)量較高,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
項(xiàng)目過程中,開始使用了js的requestAnimationFrame方法實(shí)現(xiàn)進(jìn)度條,但是在數(shù)據(jù)超級多的時(shí)候非常影響性能,如此改用css去實(shí)現(xiàn),優(yōu)化。
先貼代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style type="text/css">
*{margin: 0;padding: 0}
.box{width: 100px;height: 10px;border-radius: 10px;background: #999;margin: 100px auto;border: 1px solid #ff6780;}
.child{position: relative;height:100%;border-radius:inherit;}
.process-animate{background: #ff6780;position: absolute;left: 0;top: 0;bottom: 0;border-radius:inherit;
animation: process 1s linear forwards ;
}
@keyframes process
{
0%{
left:0;right:100%;
}
20%{
right:80%
}
40%{
right:60%;
}
60%{right:40%;}
80%{right:20%;}
100%{right:0;}
}
</style>
</head>
<body>
<p class="box">
<p class="child" style="width:50%"> // child的百分比就是進(jìn)度條的占比效果
<p class="process-animate"></p>
</p>
</p>
</body>
</html>效果圖(復(fù)制代碼可查看動態(tài)效果):

正常情況下,百分比肯定是根據(jù)后臺數(shù)據(jù)進(jìn)行計(jì)算得出的,所以是動態(tài)傳入的,下面貼vue代碼
進(jìn)度條子組件(progress.vue):
<template>
<p class="process-wrapper" :class="{'addGray':addGray}">
<p class="process-child" ref="processChild">
<p class="process-animate" :class="{'addGray':addGray}"></p>
</p>
</p>
</template>
<script>
export default {
props: {
addGray: {
//置灰
type: Boolean,
default: false
},
progressWidth: {
//進(jìn)度條百分比
type: Number,
default: 0
}
},
mounted() {
this.$nextTick(() => {
console.log(this.addGray, "addGray---");
this.$refs.processChild.style.width = this.progressWidth + "%"; //動態(tài)改變進(jìn)度條
// this.$refs.processChild.style.width = 90 + "%"; 測試效果
});
}
};
</script>
<style lang="scss" scoped>
.process-wrapper {
width: 1.98rem;
height: 0.13rem;
margin: 0.12rem 0 0.1rem 0;
border-radius: 0.1rem;
background: #fff;
border: 0.01rem solid #ff6780;
&.addGray {
background: #999;
border: 0.01rem solid #999;
}
.process-child {
position: relative;
height: 100%;
// width: 100%; //這個(gè)width就是動態(tài)變化。通過js改變
border-radius: inherit;
.process-animate {
background: #ff6780;
position: absolute;
left: 0;
top: 0;
bottom: 0;
border-radius: inherit;
animation: process 1s linear forwards;
&.addGray {
background: #999 !important;
// border: 0.01rem solid #999;
}
}
}
}
@keyframes process {
0% {
left: 0;
right: 100%;
}
20% {
right: 80%;
}
40% {
right: 60%;
}
60% {
right: 40%;
}
80% {
right: 20%;
}
100% {
right: 0;
}
}
</style>父組件調(diào)用:
<!-- 進(jìn)度條 --> <Progress :addGray="inactive" :progressWidth="progressWidth"></Progress>
看看實(shí)際效果:

以上就是css3實(shí)現(xiàn)進(jìn)度條動態(tài)效果的方法,看完之后是否有所收獲呢?如果想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊,感謝各位的閱讀。
當(dāng)前文章:css3實(shí)現(xiàn)進(jìn)度條動態(tài)效果的方法-創(chuàng)新互聯(lián)
標(biāo)題鏈接:http://chinadenli.net/article0/dpeiio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、定制開發(fā)、網(wǎng)站內(nèi)鏈、標(biāo)簽優(yōu)化、網(wǎng)站排名、ChatGPT
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容