Vue2中的进度条案例

 

v-bind对于样式控制的增强--操作style

  1. 语法: :style = “样式对象”

  2. 适用于某个具体属性的动态设置

 <div class="box" :style="{css属性名1:css属性值,css属性名2:css属性值}"></div>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 500px;
            height: 30px;
            border-radius: 50px;
            border: 1px solid #000;
        }

        .inner {
            width: 25%;
            height: 28px;
            border-radius: 50px;
            border: 1px solid #000;
            background-color: orangered;
            /*相对定位*/
            position: relative;
            /*动画*/
            transition: all 1s;

        }

        span {
            /*绝对定位*/
            position: absolute;
            right: -20px;
            bottom: -25px;
        }

        button {
            margin: 50px 20px;
            width: 80px;
            height: 30px;
        }
    </style>
</head>

<body>

    <div id="app">
        <div class="box">
            <div class="inner" :style="{width:percent + '%'}"> <!-- 动态修改percent可以修改width的宽度比例达到进度条的效果 -->
                <span>{{percent}}%</span>
            </div>
        </div>
        <button @click="percent = 25">设置25%</button>
        <button @click="percent = 50">设置50%</button>
        <button @click="percent = 75">设置75%</button>
        <button @click="percent = 100">设置100%</button>

    </div>

    <!-- 引入是开发版本的包 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>


    <script>
        const app = new Vue({
            el: '#app',
            data: {
                percent: 25
            },
            methods: {

            },
        })
    </script>
</body>

</html>

  • 8
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值