最近做了个手机端pdf预览的功能,用到pdf.js这个库,效果还不错。但是在网络差、文件大时,页面一直空白,体验不是很好。

于是加了个loading动画。

     <div id="loadingContainer">
<div class="spinner">
<div class="spinner-container container1">
<div class="circle1"></div>
<div class="circle2"></div>
<div class="circle3"></div>
<div class="circle4"></div>
</div>
<div class="spinner-container container2">
<div class="circle1"></div>
<div class="circle2"></div>
<div class="circle3"></div>
<div class="circle4"></div>
</div>
<div class="spinner-container container3">
<div class="circle1"></div>
<div class="circle2"></div>
<div class="circle3"></div>
<div class="circle4"></div>
</div>
</div>
</div>

html

 #loadingContainer {
width: 100%;
height: 100%;
display: flex;
align-items: center;
flex:;
z-index:;
.spinner {
margin: 100px auto;
width: 20px;
height: 20px;
position: relative;
.container1>div,
.container2>div,
.container3>div {
width: 6px;
height: 6px;
background-color: #fff;
border-radius: 100%;
position: absolute;
-webkit-animation: bouncedelay 1.2s infinite ease-in-out;
animation: bouncedelay 1.2s infinite ease-in-out;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.spinner-container {
position: absolute;
width: 100%;
height: 100%;
}
.container2 {
-webkit-transform: rotateZ(45deg);
transform: rotateZ(45deg);
}
.container3 {
-webkit-transform: rotateZ(90deg);
transform: rotateZ(90deg);
}
.circle1 {
top:;
left:;
}
.circle2 {
top:;
right:;
}
.circle3 {
right:;
bottom:;
}
.circle4 {
left:;
bottom:;
}
.container2 .circle1 {
-webkit-animation-delay: -1.1s;
animation-delay: -1.1s;
}
.container3 .circle1 {
-webkit-animation-delay: -1.0s;
animation-delay: -1.0s;
}
.container1 .circle2 {
-webkit-animation-delay: -0.9s;
animation-delay: -0.9s;
}
.container2 .circle2 {
-webkit-animation-delay: -0.8s;
animation-delay: -0.8s;
}
.container3 .circle2 {
-webkit-animation-delay: -0.7s;
animation-delay: -0.7s;
}
.container1 .circle3 {
-webkit-animation-delay: -0.6s;
animation-delay: -0.6s;
}
.container2 .circle3 {
-webkit-animation-delay: -0.5s;
animation-delay: -0.5s;
}
.container3 .circle3 {
-webkit-animation-delay: -0.4s;
animation-delay: -0.4s;
}
.container1 .circle4 {
-webkit-animation-delay: -0.3s;
animation-delay: -0.3s;
}
.container2 .circle4 {
-webkit-animation-delay: -0.2s;
animation-delay: -0.2s;
}
.container3 .circle4 {
-webkit-animation-delay: -0.1s;
animation-delay: -0.1s;
}
}
} @-webkit-keyframes bouncedelay {
0%,
80%,
100% {
-webkit-transform: scale(0.0)
}
40% {
-webkit-transform: scale(1.0)
}
} @keyframes bouncedelay {
0%,
80%,
100% {
transform: scale(0.0);
-webkit-transform: scale(0.0);
}
40% {
transform: scale(1.0);
-webkit-transform: scale(1.0);
}
}

scss

本以为加个DOMContentLoaded事件监视移除动画就OK了。too young too simple

DOMContentLoaded完成时,pdf文件还没下载完成。看来用错了地方。查了下api后,定位到viewer.js 行号6029

如下就是pdf加载完成回调(不同版本可能略有不同)

 loadingTask.onUnsupportedFeature = this.fallback.bind(this);
return loadingTask.promise.then(function getDocumentCallback(pdfDocument) {
self.load(pdfDocument, scale);
}, function getDocumentError(exception) {

source

修改后

 loadingTask.onUnsupportedFeature = this.fallback.bind(this);
return loadingTask.promise.then(function getDocumentCallback(pdfDocument) {
self.load(pdfDocument, scale);
var loading = document.getElementById('loadingContainer');
loading && loading.remove();
}, function getDocumentError(exception) {

target

pdf.js 添加自定义loading动画的更多相关文章

  1. loading动画效果记录

    看到好多网页都有一个炫酷的loading动画,以前不知道怎么实现的.今天学习了一下,发现其实也很简单. 首先在学习的时候偶然遇到一个pace.js的库,非常好用.优点是,不需要挂接到任何代码,自动检测 ...

  2. 纯css3 加载loading动画特效

    最近项目中要实现当页面还没有加载完给用户提示正在加载的loading,本来是想做个图片提示的,但是图片如果放大电脑的分辨率就会感觉到很虚,体验效果很不好.于是就采用css3+js实现这个loading ...

  3. 分享web前端七款HTML5 Loading动画特效集锦

    以前我们大部分的Loading动画都是利用gif图片实现的,这种图片实现Loading动画的方法虽然也很不错,但是作为HTML5开发者来说,如果能利用HTML5和CSS3实现这些超酷的Loading动 ...

  4. pdf转为html查看pdf.js

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 页面预加载loading动画,再载入内容

    默认情况下如果网站请求速度慢,所以会有一段时间的空白页面等等,用户体验效果不好,见到很多的页面都有预加载的效果,加载之前先加载一个动画,后台进程继续加载页面内容,当页面内容加载完之后再退出动画显示内容 ...

  6. 使用pdf.js实现前端页面预览pdf文档,解决了跨域请求

    pdf.js主要包含两个库文件,一个pdf.js和一个pdf.worker.js,,一个负责API解析,一个负责核心解析 官网地址:http://mozilla.github.io/pdf.js/ 下 ...

  7. electron-vue 项目添加启动loading动画问题

    前言 electron-vue脚手架搭建的项目,在开发阶段可能你注意不到项目启动慢的问题,但是在build 生成的exe可执行文件,启动后,要反应很久才能进入到app.vue 中加载的页面,体验性很差 ...

  8. 超酷!!HTML5 Canvas 水流样式 Loading 动画

    今天我们要分享另外一款基于HTML5 Canvas的液体流动样式Loading加载动画,这款Loading动画在加载时会呈现液体流动的动画效果,并且由于和背景颜色的对比,也略微呈现发光的动画效果. 效 ...

  9. 在线浏览PDF之PDF.JS (附demo)

    平台之大势何人能挡? 带着你的Net飞奔吧!:http://www.cnblogs.com/dunitian/p/4822808.html#skill 下载地址:http://mozilla.gith ...

随机推荐

  1. 【BZOJ2738】矩阵乘法 [整体二分][树状数组]

    矩阵乘法 Time Limit: 20 Sec  Memory Limit: 256 MB[Submit][Status][Discuss] Description 给你一个N*N的矩阵,不用算矩阵乘 ...

  2. Git-cheatsheet

  3. UVALIVE 5096 Volume

    This time your job is to calculate the volume of a special object. The object consists of two orthog ...

  4. Basic-Paxos原理

    Basic-Paxos //参考paxos made sample 核心是一致性协议算法. 问题 假定一个集合中的提案者可以产生一项决议. 一致性算法保证在提案者中只有一个提案可以形成决议. 如果没有 ...

  5. POI导入导出小案例

    一.HSSF 97-2003 需要jar:poi-3.9.jar 简单示例:生成EXCEL //93---2003 String [] titlie={"id","nam ...

  6. java设计模式之实现对象池模式示例分享

    http://www.jb51.net/article/46941.htm 对象池模式经常用在频繁创建.销毁对象,且对象创建.销毁开销很大的场景,比如数据库连接池.线程池.任务队列池等.本代码简单,没 ...

  7. KVM(二)CPU 和内存虚拟化

    1. 为什么需要 CPU 虚拟化 X86 操作系统是设计在直接运行在裸硬件设备上的,因此它们自动认为它们完全占有计算机硬件.x86 架构提供四个特权级别给操作系统和应用程序来访问硬件. Ring 是指 ...

  8. slatstack Master的配置

    Salt系统非常简单并且易于配置,Salt系统的两个组件都有各自的配置文件.如"salt-master"是通过主配置文件来配置的,"salt-minion"是通 ...

  9. 通过Eclipse生成可运行的jar包

    本来转自http://www.cnblogs.com/lanxuezaipiao/p/3291641.html 我是个追新潮的人,早早用上了MyEclipse10.最近需要使用Fat jar来帮我对一 ...

  10. Go语言map映射的基本操作

    对比python, java都有对应的字典类型及哈希类型. package main import ( "fmt" ) //main is the entry of the pro ...