vue實(shí)現(xiàn)百分比占比條效果
更新時(shí)間:2021年09月16日 11:41:40 作者:小包同學(xué)666
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)百分比占比條效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了vue實(shí)現(xiàn)百分比占比條的具體代碼,供大家參考,具體內(nèi)容如下
效果圖
1.各自占比
/p>
2.左百分百
3.右百分百
代碼實(shí)現(xiàn)
<template> <div class="about"> <!-- <h1>This is an about page</h1> --> <div class="step"> <!-- 左邊100%的時(shí)候不顯示斜邊三角形,并且增加右邊角 --> <div class="left" v-show="leftPercent" :class="[{ 'full-left': !rightPercent }, { 'tringle': rightPercent }]" :style="{ width: leftPercent+'%' }" @mouseover="onMouseTooltip(LEFT_BAR, SHOW_TIP)" @mouseleave="onMouseTooltip(LEFT_BAR, HIDE_TIP)" > <div class="bar-tip-box" v-show="leftBar.isShowTip"> <p>總數(shù):{{ totalNum }}</p> <p>綠色所占比例:{{ leftPercent }}%</p> </div> <div class="tip-arrow" v-show="leftBar.isShowTip"></div> {{ leftPercent }}% </div> <div class="right" v-show="rightPercent" :class="[{ 'full-right': !leftPercent }]" @mouseover="onMouseTooltip(RIGHT_BAR, SHOW_TIP)" @mouseleave="onMouseTooltip(RIGHT_BAR, HIDE_TIP)" > <div class="bar-tip-box" v-show="rightBar.isShowTip"> <p>總數(shù):{{ totalNum }}</p> <p>灰色所占比例:{{ rightPercent }}%</p> </div> <div class="tip-arrow" v-show="rightBar.isShowTip"></div> {{ rightPercent }}% </div> </div> </div> </template> <script> const LEFT_BAR = "left"; const RIGHT_BAR = "right"; const SHOW_TIP = "show"; const HIDE_TIP = "hide"; export default { data() { return { LEFT_BAR: LEFT_BAR, RIGHT_BAR: RIGHT_BAR, SHOW_TIP: SHOW_TIP, HIDE_TIP: HIDE_TIP, totalNum: 1000, leftPercent: 100, leftBar: { isShowTip: false, delayOut: null }, rightBar: { isShowTip: false, delayOut: null } }; }, methods: { onMouseTooltip(tipType, actionType) { let bar = null; if (tipType == LEFT_BAR) { bar = this.leftBar; } else if (tipType == RIGHT_BAR) { bar = this.rightBar; } else { return; } if (actionType === SHOW_TIP) { this.showBarTooltip(bar); } else if (actionType === HIDE_TIP) { this.hideBarTooltip(bar); } else { return; } }, showBarTooltip(bar) { if (bar.delayOut != null) { clearTimeout(bar.delayOut); } bar.delayOut = null; bar.isShowTip = true; }, hideBarTooltip(bar) { clearTimeout(bar.delayOut); bar.delayOut = setTimeout(function() { bar.isShowTip = false; }, 100); }, }, computed: { rightPercent: function(){ return 100 - this.leftPercent; } } }; </script> <style lang="less" scoped> .step { position: relative; display: flex; margin: 100px; width: 200px; font-size: 0; .left { flex-grow: 0; position: relative; display: inline-block; background: #62c87f; color: #fff; text-align: center; font-weight: bold; width: 70%; font-size: 12px; line-height: 20px; height: 20px; min-width: 30px; border-top-left-radius: 5px; border-bottom-left-radius: 5px; } // 百分百的時(shí)候不顯示該偽類 .tringle::after { content: " "; position: absolute; top: 0; right: -8px; border-width: 20px 8px; border-style: solid; border-color: #62c87f transparent transparent transparent; z-index: 10; } .right { flex-grow: 1; position: relative; display: inline-block; /* width:30%; */ background: #d0d4dc; color: #333; font-weight: bold; text-align: center; font-size: 12px; line-height: 20px; height: 20px; text-align: center; min-width: 35px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; } .full-left{ border-top-right-radius: 5px; border-bottom-right-radius: 5px; } .full-right{ border-top-left-radius: 5px; border-bottom-left-radius: 5px; } .tip-arrow { position: absolute; left: 50%; top: -10px; display: inline-block; width: 7px; height: 7px; transform: rotateZ(45deg); -webkit-transform: rotateZ(45deg); background-color: #7f7f7f; z-index: 10; } .bar-tip-box { position: absolute; top: -5px; right: 50%; transform: translate(50%, -100%); text-align: left; padding: 5px 10px; width: max-content; color: #fff; font-size: 12px; font-weight: 400; border-radius: 3px; background-color: #7f7f7f; z-index: 10; p { margin: 0; padding-bottom: 5px; } } } </style>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
解決vue的變量在settimeout內(nèi)部效果失效的問題
今天小編就為大家分享一篇解決vue的變量在settimeout內(nèi)部效果失效的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-08-08element-ui封裝一個(gè)Table模板組件的示例
這篇文章主要介紹了element-ui封裝一個(gè)Table模板組件的示例,幫助大家更好的理解和學(xué)習(xí)vue框架的使用,感興趣的朋友可以了解下2021-01-01vue引入jquery時(shí)報(bào)錯(cuò) $ is not defined的問題及解決
這篇文章主要介紹了vue引入jquery時(shí)報(bào)錯(cuò) $ is not defined的問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。2022-09-09vue中mock數(shù)據(jù),模擬后臺(tái)接口實(shí)例
這篇文章主要介紹了vue中mock數(shù)據(jù),模擬后臺(tái)接口實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04vue實(shí)現(xiàn)將自己網(wǎng)站(h5鏈接)分享到微信中形成小卡片的超詳細(xì)教程
在微信小程序中,可以很簡(jiǎn)單的分享一個(gè)頁面,比微信H5簡(jiǎn)單多了,下面這篇文章主要給大家介紹了關(guān)于vue實(shí)現(xiàn)將自己網(wǎng)站(h5鏈接)分享到微信中形成小卡片的超詳細(xì)教程,需要的朋友可以參考下2023-02-02