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

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

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

引入:

<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版权g4防采集https://mianka.xyz

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

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

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

标签: 前端
分享给朋友:

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

flex布局教程

父元素:display:flex;开启flex布局flex-direction 属性flex-direction:row | row-reverse | column | column=reverse;包含四个属性值:row: 默认值,表示...

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; }这样应该就行了。...

h5 input 设置必填项

html5新增了一个required属性,可以使用这个属性对文本框设置必填项,直接在input文本框上添加required即可 。例如:<input type="text" name="name" placeholder=&...

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...