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圆环进度条
数据展示,一直是各行各业乐此不疲的需求,具体到前端开发行业,则是各种各种图表数据展示,各种表格数据展示,烦不胜烦(繁不胜繁)! 前几天刚做了折线图.柱状图.饼状图之类的图表数据展示效果,今天又碰到了类 ...
随机推荐
- 洛谷 P3171 [CQOI2015]网络吞吐量 解题报告
P3171 [CQOI2015]网络吞吐量 题目描述 路由是指通过计算机网络把信息从源地址传输到目的地址的活动,也是计算机网络设计中的重点和难点.网络中实现路由转发的硬件设备称为路由器.为了使数据包最 ...
- keepalived使用nc命令检测udp端口
keepalived支持的健康检测方式有:HTTP_GET|SSL_GET.TCP_CHECK.SMTP_CHECK.MISC_CHECK. 由于keepalived自身并不支持udp检测,有TCP_ ...
- POI上传,导入excel文件到服务器1
首先说一下所使用的POI版本3.8,需要用的的Jar包: dom4j-1.6.1.jarpoi-3.8-20120326.jarpoi-ooxml-3.8-20120326.jarpoi-ooxml- ...
- Java入门:创建多个对象
当使用一个类实例化多个对象时,多个对象之间是什么关系?他们各自的数据会不会发生混淆?这次课跟大家讲解一下这个问题.学完本次课,大家应该对对象在内存中的表示方式有一个初步的了解,为理解更深入的面向对象概 ...
- php与Git下基于webhook的自动化部署
前言 2018年第一篇文章,没啥技术含量,权当笔记 我们一般都会用git或者svn来管理我们的代码 每次代码更新后还要手动的去把服务器上的代码也更新一遍 项目小了还好 项目大了着实浪费时间 要是服务器 ...
- 序列内第k小查询(线段树)
最近请教了一下大佬怎么求序列内第k大查询,自己又捣鼓了一下,虽然还没有懂得区间第k大查询,不过姑且做一个记录先吧 因为每个元素大小可能很大而元素之间不连续,所以我们先离散化处理一下,程序中的ori[ ...
- 在centos6.5安装pg
环境:centos 6.5系统,连外网. 1.参考pg官方网站进行安装.(按照上面的命令行依次执行就行) https://www.postgresql.org/download/linux/redha ...
- vue 脚手架使用
1. npm指令 vue init 模板类型 项目名称 如: vue init webpack-simple mydemo 2.进入刚才生产的 文件夹 mydemo cd mydemo 3.初始化 ...
- 一篇很棒的 MySQL 触发器学习教程
一.触发器概念 触发器(trigger):监视某种情况,并触发某种操作,它是提供给程序员和数据分析员来保证数据完整性的一种方法,它是与表事件相关的特殊的存储过程,它的执行不是由程序调用,也不是手工启动 ...
- bzoj 3309 反演
$n=p_1^{a_1}p_2^{a_2}…p_k^{a_k},p_i$为素数,定义$f(n)=max(a_1,a_2…,a_k)$. 给定a,b<=1e7求$\sum\limits_{i=1} ...