简洁的原生js百分比进度条效果

2025-10-09 15:33:09

1、新建html文档。

简洁的原生js百分比进度条效果

2、书写hmtl代码。

<!-- 代码部分begin -->

<div class="lanren">

<div id="bar" style="width:1%;"></div>

</div>

    <div class="lanren">简洁的原生js百分比进度条效果</div>

    <!-- 代码部分end -->

简洁的原生js百分比进度条效果

3、书写css代码。

<style>

*{margin:0;padding:0;list-style:none;}

.lanren{width: 450px; border: 1px solid #2BB7E4; height: 25px;margin:100px auto;}

#bar{ display: block;background: #2BB7E4; float: left; height: 100%;text-align: center;line-height: 25px; color: #FFF;} 

</style>

简洁的原生js百分比进度条效果

4、书写并添加js代码。

<script>

function $(d){

return document.getElementById(d);

}

function smation(){ 

$("bar").style.width = parseInt($("bar").style.width) + 1 + "%"; 

$("bar").innerHTML = $("bar").style.width; 

if($("bar").style.width == "100%"){ 

window.clearInterval(bar); 

}

var bar = setInterval(function(){

smation();

}, 50);; 

window.onload = function(){ bar;} 

</script>

简洁的原生js百分比进度条效果

5、代码整体结构。

简洁的原生js百分比进度条效果

6、查看效果。

简洁的原生js百分比进度条效果

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢