
【推荐教程:CSS视频教程 】
一、顶部进度条
在html代码中间插入jq代码 执行动画。页面加载到哪部分,进度条就会相应的向前走多少
立即学习“前端免费学习笔记(深入)”;
当全部加载完成后将loading进度条模块隐藏
顶部进度条 .loading {position: fixed;top: 0;left: 0; width: 100%; height: 100%; background-color: #fff;} .pic {width: 0;height: 10px;background-color: #c33;border-radius: 5px;}@@##@@ @@##@@ $(".loading .pic").animate({width: "20%"},100);@@##@@ @@##@@ $(".loading .pic").animate({width: "40%"},100);@@##@@ @@##@@ $(".loading .pic").animate({width: "60%"},100);@@##@@ $(".loading .pic").animate({width: "80%"},100); $(".loading .pic").animate({width: "100%"},100, function() { $(".loading").fadeOut(); });
二、直接在页面插入关于加载的动态图,页面加载完再隐藏掉
关于图片可以在这个网站找:https://loading.io/ 可以根据自己的需求调样式
当然,如果想自己写也可以,下面是博主自己用css3写的一个小动画
代码如下
css3动画进度条 .loading {position: fixed;top:0;left:0;width: 100%; height: 100%;background-color: #fff;} .pic {position: absolute;top: 0;bottom: 0;left: 0;right: 0;margin: auto;width: 100px;height:40px;} .pic i {float:left;margin: 0 2px;width: 6px;height: 30px;background-color: indigo;transform: scaleY(0.4);animation: load 1.2s infinite;} .pic i:nth-child(2){-webkit-animation-delay: 0.1s;animation-delay: 0.1s;} .pic i:nth-child(3){-webkit-animation-delay: 0.2s;animation-delay: 0.2s;} .pic i:nth-child(4){-webkit-animation-delay: 0.3s;animation-delay: 0.3s;} .pic i:nth-child(5){-webkit-animation-delay: 0.4s;animation-delay: 0.4s;} .pic i:nth-child(6){-webkit-animation-delay: 0.5s;animation-delay: 0.5s;} @-webkit-keyframes load { 0%,40%,100%{-webkit-transform: scaleY(0.4); transform: scaleY(0.4)} 20%{-webkit-transform: scaleY(1); transform: scaleY(1)} } @keyframes load { 0%,40%,100%{-webkit-transform: scaleY(0.4); transform: scaleY(0.4)} 20%{-webkit-transform: scaleY(1); transform: scaleY(1)} } document.onreadystatechange = function() { // 页面状态发生改变时触发 if(document.readyState == "complete") { // 页面加载完成时隐藏 $(".loading").fadeOut(); } }@@##@@ @@##@@ @@##@@ @@##@@ @@##@@ @@##@@ @@##@@ @@##@@ @@##@@
三、实时获取数据的进度条(百分比)
代码如下
百分比进度条 .loading {position: fixed;top:0;left:0;width: 100%; height: 100%;background-color: #fff;} .pic {position: absolute;top: 0;bottom: 0;left: 0;right: 0;margin: auto;width: 100px;height:100px;line-height: 55px;text-align: center;font-size: 22px;} .pic span {display: inline-block;position: absolute;top: 10px;left: 10px;width: 80px;height: 80px;border-radius: 50%;box-shadow: 0 3px 0 #999; -webkit-animation: move 1s infinite linear;animation: move 1s infinite linear;} @-webkit-keyframes move { 0%{-webkit-transform: rotate(0deg);transform: rotate(0deg);} 100%{-webkit-transform: rotate(360deg);transform: rotate(360deg);} } @keyframes move { 0%{-webkit-transform: rotate(0deg);transform: rotate(0deg);} 100%{-webkit-transform: rotate(360deg);transform: rotate(360deg);} } $(function() { var img = $("img"); // 获取所有的img元素 var num = 0; // 用来存储已加载的图片个数 img.each(function(i) { // 遍历所有图片 var oImg = new Image(); oImg.onload = function() { // onload 图片加载完成后执行 num++; $(".pic p").html(parseInt(num / img.length * 100) + '%'); if(num >= img.length) { $(".loading").fadeOut(); // 页面加载完成后隐藏 } } oImg.src = img[i].src; }) })@@##@@ @@##@@ @@##@@ @@##@@ @@##@@ @@##@@ @@##@@ @@##@@ @@##@@0%
更多编程相关知识,请访问:编程视频!!




以上就是浅谈jQuery+CSS实现前端网页加载进度条的三种方式的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1618052.html
微信扫一扫
支付宝扫一扫