当前位置:首页 > 前端 > 正文内容

使用NProgress.js制作一个相对准确的网页加载进度条

zhangsir3年前 (2022-11-08)前端346

引入:

<link href="https://www.haohaokan17.com/js/nprogress.css" rel="stylesheet" />
<script src="https://www.haohaokan17.com/static/js/jquery.min.js"></script>
<script src="https://www.haohaokan17.com/js/nprogress.js"></script>

html:

<div class="progress">   
  <div></div>
</div>

css:

<style>
    .progress {   width: 100%;   height: 1px; } 
    .progress div {   width: 0;   height: 100%;   background: green; transition: width .5s;}
</style>

js:

document.addEventListener('readystatechange', function () {   
  if(document.readyState === 'interactive') {     
     document.querySelector('.progress div').style.width = '33%'  
  }    
  if(document.readyState === 'complete') {
     document.querySelector('.progress div').style.width = '66%'   
  } 
} ) 
window.onload = function () {
   document.querySelector('.abc div').style.width = '100%' 
}

添加以上代码就可以给你的网站添加一个进度条了。

zhangsir版权h8防采集https://mianka.xyz

扫描二维码推送至手机访问。

版权声明:本文由zhangsir or zhangmaam发布,如需转载请注明出处。

本文链接:http://mianka.xyz/post/61.html

标签: 前端
分享给朋友:

“使用NProgress.js制作一个相对准确的网页加载进度条” 的相关文章

ajax库Axios的使用方法

axios简介Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。axios的基本使用如何引入axios可以通过npm安装来进行使用npm install axio也可以使用 bower进行安装,然后在页面中进行引入:bower&nbs...

css如何设置input聚焦时的样式

input的聚焦时的样式怎么设置呢?input:focus-visible {   background-color: red; }这样应该就行了。...

autojs强制关闭APP详解

// 测试手机为红米note10 pro,autojsPro版本8.8.22-common killApp("微信"); function killApp(appName) {//填写包名或app名称都可以   &...

layui框架引入css文件不报错也不生效

layui框架引入css文件不报错也不生效link加入rel=“stylesheet” type=“text/css” 属性即可实例<link type="text/css" rel="stylesheet" href=&q...

jquery如何获取最后一个元素

jquery如何获取最后一个元素获取最后一个元素,并将文字设置为红色$(document).ready(function(){     $(p).last().css(color,red); });相关扩展:使用first()方法获取第一个元素#获取第一个...

jquery获取元素有两个,怎么获取第二个的属性名

如果你有两个相同类型的且具有相同类名或ID的元素,你可以使用jQuery的.eq()方法来获取第二个元素的属性名。这个方法返回指定元素的属性名。例如,假设你有两个div元素,它们都有class="myDiv",你可以这样获取第二个元素的class属性名:$('.myDiv...