当前位置:首页 > 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 是什么? jQuery 是一个轻量级的 JavaScript 库,简…

jquery之家

jquery之家

jQuery之家相关资源 jQuery之家是一个提供jQuery插件、教程和资源的网站,适合开发者学习和使用jQuery技术。以下是关于jQuery之家的主要内容和资源: 网站内容 提供丰…

jquery和vue的区别

jquery和vue的区别

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

vue请求实现进度条

vue请求实现进度条

实现请求进度条的方法 在Vue中实现请求进度条可以通过多种方式完成,常见的有使用axios拦截器和第三方库如NProgress。以下是具体实现方法: 使用axios拦截器配合NProgress 安装…

vue实现水波球进度条

vue实现水波球进度条

实现水波球进度条的方法 使用 SVG 和 CSS 动画 创建一个圆形 SVG 元素,通过 CSS 动画实现水波效果。定义一个波浪路径,使用 animateTransform 或 CSS keyfram…

js 进度条的实现

js 进度条的实现

使用 HTML 和 CSS 创建基础进度条 HTML 结构可以简单使用一个 div 元素作为容器,内部嵌套另一个 div 表示进度: <div class="progress-contain…