当前位置:首页 > jquery

jquery进度条

2026-01-16 14:44:43jquery

jquery进度条

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 Official Documentation 内容分类:API 参考:包含所…

jquery添加

jquery添加

jQuery 添加元素的方法 在jQuery中,添加元素到DOM有多种方式,可以根据需求选择合适的方法。 append() 将内容插入到选定元素的内部末尾处。 $("#container").ap…

jquery 属性

jquery 属性

jQuery 属性操作 jQuery 提供了一系列方法来获取、设置和操作 HTML 元素的属性。以下是常用的属性操作方法: attr() 方法 用于获取或设置元素的属性值。获取属性时,传入属性名;设…

下载jquery

下载jquery

下载 jQuery 的方法 官方网站下载 访问 jQuery 的官方网站 https://jquery.com,点击页面上的“Download”按钮。选择压缩版(minified)或未压缩版(unco…

jquery时间

jquery时间

jQuery 时间处理 jQuery 本身不提供专门的时间处理函数,但可以通过 JavaScript 的 Date 对象结合 jQuery 的事件和方法来实现时间操作。以下是常见的时间处理需求及实现方…

jquery滑动

jquery滑动

jQuery 滑动效果实现方法 使用 slideDown() 和 slideUp() slideDown() 用于向下滑动显示元素,slideUp() 用于向上滑动隐藏元素。两者均可设置动画持续时间(…