一个用vue写的进度条(仅仅是个小测试,很简单,需要的自行复制粘贴!!别忘了给个关注。)

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <meta http-equiv="X-UA-Compatible" content="IE=edge">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>小帅进度条</title>

  <style>

    .progress {

      height: 25px;

      width: 800px;

      border-radius: 15px;

      background-color: #272425;

      border: 3px solid #272425;

      box-sizing: border-box;

      margin-bottom: 30px;

    }

    .inner {

      width: 50%;

      height: 20px;

      border-radius: 10px;

      text-align: right;

      position: relative;

      background-color: #409eff;

      background-size: 20px 20px;

      box-sizing: border-box;

      transition: all 1s;

    }

    .inner span {

      position: absolute;

      right: -20px;

      bottom: -25px;

    }

     button {

      /* 基本样式 */

      padding: 10px 20px;

      font-size: 16px;

      border: none;

      cursor: pointer;

      background-color: skyblue; /* 初始背景色 */

      color: white; /* 初始文字颜色 */

      transition: all 0.3s ease; /* 添加过渡效果 */

    }

    button:hover {

      /* 鼠标悬停时的样式 */

      background-color: pink; /* 改变背景色 */

      color: lightgray; /* 改变文字颜色 */

    }

  button:active {

      /* 按下时的样式 */

      background-color: salmon; /* 更深的背景色以模拟按下效果 */

      box-shadow: inset 0 5px 10px rgba(0,0,0,0.2); /* 添加内阴影 */

      transform: translateY(1px); /* 微微上移,增加按压感 */

    }

  </style>

</head>

<body>

  <h1>小帅进度条</h1>

  <div id="app">

    <!-- 外层盒子底色 (黑色) -->

    <div class="progress">

      <!-- 内层盒子 - 进度(蓝色) -->

      <div class="inner" :style="{ width: percent + '%' }">

        <span>{{ percent }}%</span>

      </div>

    </div>

    <button v-show="index>0" @click="index--">上一页</button>

    <button @click="percent = 25,index++">设置25%</button>

    <button @click="percent = 50,index++">设置50%</button>

    <button @click="percent = 75,index++">设置75%</button>

    <button @click="percent = 100,index++">设置100%</button>

    <button @click="index=0,percent=30">恢复</button>

    <div><img :src="list[index]" v-show="index>0" alt=""></div>

   

  </div>

  <!-- <img src="imgs/11-00.gif" alt=""> -->

  <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>

  <script>

    const app = new Vue({

      el: '#app',

      data: {

        percent: 30,

        index:0,

        //数组里面的图片素材自行添加谢谢!

        list:[

          'imgs/11-00.gif',

          'imgs/11-01.gif',

          'imgs/11-02.gif',

          'imgs/11-03.gif',

      ]

      }

     

    })

  </script>

</body>

</html>

  • 15
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
1. 安装vue-cli 如果您尚未安装vue-cli,请使用以下命令进行安装: ``` npm install -g vue-cli ``` 2. 创建Vue项目 使用vue-cli创建一个新的Vue项目: ``` vue init webpack progress-bar ``` 进入项目文件夹并安装依赖: ``` cd progress-bar npm install ``` 3. 创建ProgressBar组件 在src/components文件夹中创建一个名为ProgressBar.vue的组件。 在组件中添加以下代码: ```html <template> <div class="progress-bar"> <div class="progress" :style="{ width: progress + '%' }"></div> </div> </template> <script> export default { props: ['progress'], }; </script> <style> .progress-bar { width: 100%; height: 20px; background-color: #e0e0e0; } .progress { height: 100%; background-color: #4caf50; transition: width 0.3s ease-in-out; } </style> ``` 这个组件有一个名为progress的属性,用于指定进度百分比。在模板中,我们将进度条作为一个div元素呈现,并使用动态样式将其宽度设置为进度的百分比。 4. 在App.vue中使用ProgressBar组件 在App.vue中添加以下代码: ```html <template> <div id="app"> <h1>Progress Bar Demo</h1> <ProgressBar :progress="progress" /> <button @click="startProgress">Start</button> </div> </template> <script> import ProgressBar from './components/ProgressBar.vue'; export default { name: 'App', components: { ProgressBar, }, data() { return { progress: 0, }; }, methods: { startProgress() { const intervalId = setInterval(() => { if (this.progress < 100) { this.progress += 10; } else { clearInterval(intervalId); } }, 1000); }, }, }; </script> ``` 在模板中,我们使用ProgressBar组件将进度条呈现为页面的一部分。我们还添加了一个按钮,以触发进度条的增长。 在脚本中,我们使用data属性来定义一个名为progress的变量,并初始化为0。我们还定义了一个名为startProgress的方法,该方法使用setInterval函数来增加进度条的值,并在达到100时停止增长。 5. 运行Vue项目 使用以下命令启动Vue项目: ``` npm run dev ``` 打开浏览器并访问http://localhost:8080,您应该可以看到一个简单进度条一个按钮。单击按钮,进度条应该开始增长。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风流野趣fly

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值