当前位置:首页 > 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 Less, Do More”,…

jquery 菜鸟

jquery 菜鸟

jQuery 入门指南 jQuery 是一个快速、简洁的 JavaScript 库,简化了 HTML 文档遍历、事件处理、动画和 Ajax 交互。以下内容适合初学者快速上手。 引入 jQuery 在…

jquery怎么读

jquery怎么读

jQuery的发音 jQuery的正确发音为 "jay-query"(/ˈdʒeɪkwɪəri/)。其中: "jay" 发字母 "J" 的音(如英文单词 "jump" 的首音)。 "query" 读…

jquery文档

jquery文档

以下是关于 jQuery 文档的核心资源和使用方法整理: jQuery 官方文档 jQuery 官方文档是学习和使用 jQuery 最权威的资源,包含详细的 API 说明、示例和更新日志。…

js 进度条的实现

js 进度条的实现

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

jquery官网

jquery官网

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