当前位置:首页 > jquery

jquery进度条

2026-01-16 14:44:43jquery

jQuery 进度条实现方法

使用 HTML5 <progress> 元素结合 jQuery

<progress id="fileProgress" value="0" max="100"></progress>
<button id="startBtn">开始加载</button>
$('#startBtn').click(function() {
  var progress = 0;
  var interval = setInterval(function() {
    progress += 10;
    $('#fileProgress').val(progress);
    if(progress >= 100) clearInterval(interval);
  }, 500);
});

使用 jQuery UI Progressbar 组件

<link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>

<div id="progressbar"></div>
$("#progressbar").progressbar({
  value: 0
});

function updateProgress() {
  var currentValue = $("#progressbar").progressbar("value");
  if(currentValue < 100) {
    $("#progressbar").progressbar("value", currentValue + 10);
    setTimeout(updateProgress, 500);
  }
}

updateProgress();

自定义 CSS 进度条控制

<div class="progress-container">
  <div class="progress-bar"></div>
</div>
<button class="progress-btn">开始进度</button>
.progress-container {
  width: 100%;
  background-color: #ddd;
  border-radius: 5px;
}

.progress-bar {
  height: 20px;
  width: 0%;
  background-color: #4CAF50;
  border-radius: 5px;
  transition: width 0.3s;
}
$('.progress-btn').click(function() {
  var width = 0;
  var interval = setInterval(function() {
    if(width >= 100) {
      clearInterval(interval);
    } else {
      width++;
      $('.progress-bar').css('width', width + '%');
    }
  }, 50);
});

使用 Bootstrap 进度条

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

<div class="progress">
  <div id="bootstrapProgress" class="progress-bar" role="progressbar" style="width: 0%"></div>
</div>
var progress = 0;
var interval = setInterval(function() {
  progress += 5;
  $('#bootstrapProgress').css('width', progress + '%').attr('aria-valuenow', progress);
  if(progress >= 100) clearInterval(interval);
}, 300);

动画效果增强

$('#animatedProgress').animate({
  width: '100%'
}, {
  duration: 2000,
  step: function(now) {
    $(this).text(Math.round(now) + '%');
  }
});

以上方法提供了从简单到复杂的多种 jQuery 进度条实现方案,可根据项目需求选择适合的方式。jQuery UI 方案提供了最完整的 API 支持,而自定义 CSS 方案则具有更好的灵活性。

jquery进度条

jquery进度条

标签: 进度条jquery
分享给朋友:

相关文章

jquery教程

jquery教程

jQuery 简介 jQuery 是一个快速、简洁的 JavaScript 库,简化了 HTML 文档遍历、事件处理、动画设计和 Ajax 交互。其核心特点是“写得更少,做得更多”(Write Les…

jquery api

jquery api

jQuery 是一个快速、简洁的 JavaScript 库,简化了 HTML 文档遍历、事件处理、动画和 Ajax 交互。以下是 jQuery API 的核心功能和使用方法: 选择器 jQuery…

jquery和vue的区别

jquery和vue的区别

jQuery 和 Vue.js 的区别 jQuery 和 Vue.js 是两种不同的前端技术,分别适用于不同的场景和开发需求。以下是它们的主要区别: 设计理念 jQuery 是一个轻量级的 Java…

jquery官网

jquery官网

jQuery 官网地址 jQuery 的官方网站是 https://jquery.com/。该网站提供以下核心内容: 下载 jQuery:提供最新版本的 jQuery 库(压缩版和未压缩版),支持…

jquery和vue的区别

jquery和vue的区别

核心设计理念 jQuery是一个基于DOM操作的轻量级JavaScript库,主要用于简化HTML文档遍历、事件处理、动画设计等任务。它采用命令式编程风格,需要手动操作DOM元素。 Vue是一个渐进…

jquery获取radio选中的值

jquery获取radio选中的值

获取radio选中的值 使用jQuery获取被选中的radio按钮的值可以通过以下几种方法实现: 方法1:使用:checked选择器 var selectedValue = $('input[…