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圆环进度条
数据展示,一直是各行各业乐此不疲的需求,具体到前端开发行业,则是各种各种图表数据展示,各种表格数据展示,烦不胜烦(繁不胜繁)! 前几天刚做了折线图.柱状图.饼状图之类的图表数据展示效果,今天又碰到了类 ...
随机推荐
- 【AGC003F】Fraction of Fractal
Description 原题链接 Solution 神题. 定义一个上边界或下边界的格子为"上下接口",当且仅当上下边界该位置的格子都是黑色的. "左 ...
- 音视频处理之FFmpeg+SDL视频播放器20180409
一.FFmpeg视频解码器 1.视频解码知识 1).纯净的视频解码流程 压缩编码数据->像素数据. 例如解码H.264,就是“H.264码流->YUV”. 2).一般的视频解码流程 视频码 ...
- @Html.DropDownListFor默认选中项
http://q.cnblogs.com/q/73902/ 项目使用mvc4,给dropDownList指定默认值未选中 页面代码是: 1.未有默认选中值 Html.DropDownListFor(m ...
- P2207 Photo
P2207 Photo 题目描述 Framer Jhon 打算给他的N头奶牛照相,( 2 <= N <= 1 000 000 000) . 他们排成一条线,并且依次取1~N作为编号. 每一 ...
- classpath 及读取 properties 文件
java代码中获取项目的静态文件,如获取 properties 文件内容是必不可少的. Spring 下只需要通过 @Value 获取配置文件值 <!-- 资源文件--> <util ...
- String详解, String和CharSequence区别, StringBuilder和StringBuffer的区别
本章主要介绍String和CharSequence的区别,以及它们的API详细使用方法. 转载请注明出处:http://www.cnblogs.com/skywang12345/p/string01. ...
- bzoj千题计划167:bzoj3527: [Zjoi2014]力
http://www.lydsy.com/JudgeOnline/problem.php?id=3527 给出n个数qi,给出Fj的定义如下: 令Ei=Fi/qi,求Ei. 以n=4为例: ...
- 【学习DIV+CSS】2. 学习CSS(一)--CSS控制页面样式
1. CSS如何控制页面 使用XHTML+CSS布局页面,其中有一个很重要的特点就是“结构与表现相分离”(结构指XHTML,表现指CSS).有人这样描述这种分离的关系,结构XHTML好比一个人,表现C ...
- 把JS和CSS合并到1个文件
合并JS文件和CSS文件很多人都知道,也用过,目的是为了减少请求数.但有时候我们觉的把JS合并到1个文件,CSS又合并到另外1个文件也是浪费,我们如何能把CSS和JS一起合并进1个文件了? 这里需要使 ...
- 20155231 2016-2017-2 《Java程序设计》第7周学习总结
20155231 2016-2017-2 <Java程序设计>第7周学习总结 教材学习内容总结 学习目标 了解Lambda语法 了解方法引用 了解Fucntional与Stream API ...