Vue 实现loading进度条
项目中遇到的,用vue实现下:

<template>
<div class="plLoading">
<div class="plLoadingContent">
<div class="plLoadingLogo">
<img src="http://static.crecgec.com/Kaipiao/loadingLogo.png"/>
</div>
<div class="plLoadingCon">
<div class="plLoadingShow" ref="plLoadingShow" :style="{width: plsStyleWidth}"></div>
<div class="plLoCir" ref="plLoCir" :style="{left: plcStyleLeft}" v-show="plcShow"></div>
</div>
<div class="plLoadingNum" ref="plLoadingNum">%</div>
</div>
<!--测试用的,使用的时候,在父组件创建一个隐藏的Ddiv,里面放入这个页面用到的所有img-->
<div class="imgsHidden displayNone">
<img class="hImg" src="http://static.crecgec.com/Kaipiao/countDownTitle.png">
<img class="hImg" src="http://static.crecgec.com/Kaipiao/countDown.png">
<img class="hImg" src="http://static.crecgec.com/Kaipiao/countDown1.png">
<img class="bImg" src="http://static.crecgec.com/Kaipiao/background.png">
<img class="hImg" src="http://static.crecgec.com/Kaipiao/loadingLogo.png">
</div>
</div>
</template> <script type="text/ecmascript-6">
import $ from 'jquery' export default {
props: {
eleH: {
type: String,
default: 'hImg'
},
eleB: {
type: String,
default: 'bImg'
},
dataIsOk: {
type: Boolean,
default: false
}
},
data () {
return {
plsStyleWidth: , // plLoadingShow的初始width
plcStyleLeft: , // plLoCir的初始left值
plcShow: true, // plLoCir初始是显示状态
backImgLoading: false, // 背景图片是否加载成功(40)
otherImgLoading: false, // 头部、底部图片加载成功(40)
dataLoading: '', // 后台返回的数据加载成功(20)
lodingWidth: ,
otherImgLength: ,
otherNum: ,
backImgLength: ,
backNum:
}
},
watch: {
// 整个也没被分为三部分:背景图、其他图片、数据
// 监控otherImgLoading,(其他图片加载成功),this.lodingWidth增加40
otherImgLoading () {
this.lodingWidth = this.lodingWidth +
},
// 监控otherImgLoading,(背景图片加载成功),this.lodingWidth增加40
backImgLoading () {
this.lodingWidth = this.lodingWidth +
},
// 监控dataIsOk,(数据加载成功,这个有父组件传递过来),this.lodingWidth增加20
dataIsOk () {
if (this.dataIsOk) {
this.lodingWidth = this.lodingWidth +
}
},
// 监控lodingWidth的值
lodingWidth () {
if (this.lodingWidth <= ) {
this.setLoadingWidthTimer(this.lodingWidth)
}
},
// 监控plcStyleLeft(圆球的left值),如果值为484px(自己设置的),表明圆球到了最右边
// 圆球隐藏
plcStyleLeft () {
if (this.plcStyleLeft === '484px') {
setTimeout(() => {
this.plcShow = false
this.hasScroll()
this.$emit('tipShow', {loadingIsShow: false})
}, )
}
}
},
mounted () {
this.isOtherImgLoading(this.eleH)
this.isBackImgLoading(this.eleB)
this.noScroll()
},
methods: {
// 设置width、left
setLoadingWidthTimer (newPllsWidth) {
if (newPllsWidth <= ) {
setTimeout(() => {
this.plsStyleWidth = ( * newPllsWidth / ) + 'px'
this.plcStyleLeft = ( * newPllsWidth / ) + 'px'
this.$refs.plLoadingNum.innerHTML = newPllsWidth + '%'
}, )
} else if (newPllsWidth <= ) {
setTimeout(() => {
this.plsStyleWidth = ( * newPllsWidth / ) + 'px'
this.plcStyleLeft = ( * newPllsWidth / ) + 'px'
this.$refs.plLoadingNum.innerHTML = newPllsWidth + '%'
}, )
} else {
setTimeout(() => {
this.plsStyleWidth = ( * newPllsWidth / ) + 'px'
this.plcStyleLeft = ( * newPllsWidth / ) + 'px'
this.$refs.plLoadingNum.innerHTML = newPllsWidth + '%'
}, )
}
},
// 弹出层显示的时候,没有滚动条
noScroll () {
document.body.style.cssText = 'overflow:hidden;'
},
// 弹出层消失后,滚动条显示
hasScroll () {
document.body.style.cssText = 'overflow:auto;'
},
isOtherImgLoading (ele) {
this.otherImgLength = $('.' + ele).length
let _this = this
if (this.otherImgLength > ) {
$('.' + ele).each(function () {
$(this).on('load', function () {
_this.otherNum = _this.otherNum +
if (_this.otherImgLength === _this.otherNum) {
_this.otherImgLoading = true
}
})
})
} else {
this.otherImgLoading = true
}
},
isBackImgLoading (ele) {
this.backImgLength = $('.' + ele).length
let _this = this
if (this.backImgLength > ) {
$('.' + ele).each(function () {
$(this).on('load', function () {
_this.backNum = _this.backNum +
if (_this.backImgLength === _this.backNum) {
_this.backImgLoading = true
}
})
})
} else {
this.backImgLoading = true
}
}
}
}
</script> <style>
.plLoading{
width: %;
height: %;
position: absolute;
left: ;
top: ;
z-index: ;
background-color: #00101d;
}
.plLoadingContent{
width: 500px;
height: 220px;
position: absolute;
margin: auto;
top: %;
left: %;
margin-top: -110px;
margin-left: -250px;
}
.plLoadingLogo{
height: 60px;
}
.plLoadingCon{
width: 500px;
height: 16px;
margin-top: 100px;
border-radius: 8px;
background-color: #;
}
.plLoadingShow{
transition: width .5s;
height: 16px;
border-radius: 8px;
background-color: #0062b2;
position: absolute;
}
.plLoCir{
transition: left .5s;
position: absolute;
width: 16px;
height: 16px;
border-radius: 8px;
background-color: #0062b2;
box-shadow: 20px #008cff;
}
.plLoadingNum{
font-size: 14px;
color: #0062b2;
margin-top: 20px;
}
.displayNone{
display: none;
}
</style>
Vue 实现loading进度条的更多相关文章
- Android loading进度条使用简单总结
在这里,总结一下loading进度条的使用简单总结一下. 一.说起进度条,必须说说条形进度条,经常都会使用到嘛,特别是下载文件进度等等,还有像腾讯QQ安装进度条一样,有个进度总给人良好的用户体验. 先 ...
- JavaScript之Loading进度条
一个loading进度条,定义一个fakeProgress方法,定位一个URL,然后setTimeout设置跳转时间我们就能看到我们要打开的URL网址了. 这个链接我就直接链接到我的新浪博客去了,算是 ...
- ASP.NET 给Web中的网页添加Loading进度条形式
前段时间客户提了一个需求,要求给网站中某些功能添加进度条形式,因为某些功能查询的数据量太大,经常会出现点击Search按钮,但是没有任何反应的情况,会让用户以为网站挂掉了,导致投诉的事情发生,所以客户 ...
- 模态框的理解 ,jQ: loading,进度条, 省级联动 表单验证 插件
模态框: 打开一个弹框 不关闭它就不能做框外的操作 必须关闭或弹出另外的弹框 加载延迟loading + 进度条只要有请求 就处理一下监控ajax 全局事件jquery: $('#box').ajax ...
- Unity3d中制作异步Loading进度条所遇到的问题
背景 通常游戏的主场景包括的资源较多,这会导致载入场景的时间较长.为了避免这个问题,能够首先载入Loading场景.然后再通过Loading场景来载入主场景. 由于Loading场景包括的资源较少,所 ...
- vue轻量进度条
**### vue------ mode 好玩东西+1: 轻量级进度条: 1.引入 import NProgress from 'nprogress'; // progress bar import ...
- spin.js无图片实现loading进度条,支持但非依赖jquery
特点: 1.无图片,无外部CSS 2.无依赖(支持jQuery,但非必须) 3.高度可配置 4.分辨率无关 5.旧版本IE不支持时,采用VML支持 6.使用关键帧动画,采用setTimeout() 7 ...
- unity3d___UGui中如何创建loading...进度条
http://blog.sina.com.cn/s/blog_e82e8c390102wh2z.html 实现方法:通过Image组件中Image Type属性中Fill Amount,通过代码改变F ...
- Vue/React圆环进度条
数据展示,一直是各行各业乐此不疲的需求,具体到前端开发行业,则是各种各种图表数据展示,各种表格数据展示,烦不胜烦(繁不胜繁)! 前几天刚做了折线图.柱状图.饼状图之类的图表数据展示效果,今天又碰到了类 ...
随机推荐
- 《Linux内核分析》期末总结及学习心得
[洪韶武 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 ] 一.学习心得 本学 ...
- CentOS7搭建elasticsearch集群
准备三个节点,系统版本为CentOS7.3. 11.0.10.18 es01 11.0.10.19 es02 11.0.10.20 es03 1.安装java环境 # yum install -y j ...
- Android Studio中多项目共享Library
FAQ: as的projectA中有一个commonLib的源码库模块,projectB要调用其中的commonLib, 这个有没有方案?不用手动拷贝aar的 方案1. 采用gradle配置参数方 ...
- 解题:CQOI 2017 老C的方块
题面 看起来很像网络流的二分图套路题,然后我们大力观察(题目定义的相邻我用引号括起来,应该能看懂) 发现“相邻”的一对方格如果各自连着一个一个方格就gg了,于是对于所有这些“相邻”的方格,我们有两种选 ...
- loj2542「PKUWC2018」随机游走
题目描述 给定一棵 nn 个结点的树,你从点 xx 出发,每次等概率随机选择一条与所在点相邻的边走过去. 有 QQ 次询问,每次询问给定一个集合 SS,求如果从 xx 出发一直随机游走,直到点集 SS ...
- OCR论文整理
论文地址:https://github.com/ChanChiChoi/awesome-ocr 下面是已经看过的论文: CTPN CRNN TextBoxes EAST FOTS PixelLink
- postgresql 数据库无法启动
在数据库无法启动时,一般可以根据报错信息,采取对应措施即可,下面列出一些在数据库启动时报出错误比较严重而解决方式又不那么明显的处理方法. 模拟错误,查到pg_class系统表中一个索引在磁盘中的位置, ...
- 虚拟机中在centos6.7环境下安装eclipse
采用的是在线安装的方式,所以省去了很多配置环境变量的步骤,经过以下5步. 1, yum install eclipse 2, 安装xmanager -> windows下远程eclipse可 ...
- UVAL 7902 2016ECfinal F - Mr. Panda and Fantastic Beasts
题意: 给出n个串,求一个最短的第一个串的子串使它不在其他的n-1个串中出现,若有多个求字典序最小的. Limits: • 1 ≤ T ≤ 42. • 2 ≤ N ≤ 50000. • N ≤ S1 ...
- Python【requests】第三方模块
import requests print("===============get请求================")url = 'http://api.nnzhp.cn/ap ...