几个简单的加载中动画吧。
像前面三种都是相当于几个不同的点轮流来播放同一动画:变大变小。css3里面有一个用于尺度变换的方法:scale(x,y):定义 2D 缩放转换,改变元素的宽度和高度。
第四种就是一个小球从上往下跌落,再弹回去,在上面的时候速度最小,下面的时候速度最大。由于该小球只进行了上下的移动,所以我们可以运用:translateY(n):定义 2D 转换,沿着 Y 轴移动元素,从而实现小球沿Y方向来回移动。
废话不多说了,上代码。
首先,第一个加载中的动画:
html Code
<div id="loading1">
<div class="demo1"></div>
<div class="demo1"></div>
<div class="demo1"></div>
<div class="demo1"></div>
<div class="demo1"></div>
</div>
css Code
.demo1 {
width: 4px;
height: 4px;
border-radius: 2px;
background: #68b2ce;
float: left;
margin: 0 3px;
animation: demo1 linear 1s infinite;
-webkit-animation: demo1 linear 1s infinite;
}
.demo1:nth-child(1){
animation-delay:0s;
}
.demo1:nth-child(2){
animation-delay:0.15s;
}
.demo1:nth-child(3){
animation-delay:0.3s;
}
.demo1:nth-child(4){
animation-delay:0.45s;
}
.demo1:nth-child(5){
animation-delay:0.6s;
}
@keyframes demo1
{
0%,60%,100% {transform: scale(1);}
30% {transform: scale(2.5);}
}
@-webkit-keyframes demo1
{
0%,60%,100% {transform: scale(1);}
30% {transform: scale(2.5);}
}
css Code
第二个动画和第一个动画大同小异,第一个动画是将小球整体变大变小,第二动画则是将小方块的高度变大变小,而宽度不变:
html Code
<div id="loading2">
<div class="demo2"></div>
<div class="demo2"></div>
<div class="demo2"></div>
<div class="demo2"></div>
<div class="demo2"></div>
</div>
css Code
.demo2 {
width: 4px;
height: 6px;
background: #68b2ce;
float: left;
margin: 0 3px;
animation: demo2 linear 1s infinite;
-webkit-animation: demo2 linear 1s infinite;
}
.demo2:nth-child(1){
animation-delay:0s;
}
.demo2:nth-child(2){
animation-delay:0.15s;
}
.demo2:nth-child(3){
animation-delay:0.3s;
}
.demo2:nth-child(4){
animation-delay:0.45s;
}
.demo2:nth-child(5){
animation-delay:0.6s;
}
@keyframes demo2
{
0%,60%,100% {transform: scale(1);}
30% {transform: scaleY(3);}
}
@-webkit-keyframes demo2
{
0%,60%,100% {transform: scale(1);}
30% {transform: scaleY(3);}
}
css Code
第三个动画就需要将小球的位置定位一下,让几个小球整体上看起来围成一个圆,然后就像第一个一样使小球变大变小:
html Code
<div id="loading1">
<div class="demo1"></div>
<div class="demo1"></div>
<div class="demo1"></div>
<div class="demo1"></div>
<div class="demo1"></div>
</div>
css Code
#loading3 {
position: relative;
width: 50px;
height: 50px;
}
.demo3 {
width: 4px;
height: 4px;
border-radius: 2px;
background: #68b2ce;
position: absolute;
animation: demo3 linear 0.8s infinite;
-webkit-animation: demo3 linear 0.8s infinite;
}
.demo3:nth-child(1){
left: 24px;
top: 2px;
animation-delay:0s;
}
.demo3:nth-child(2){
left: 40px;
top: 8px;
animation-delay:0.1s;
}
.demo3:nth-child(3){
left: 47px;
top: 24px;
animation-delay:0.1s;
}
.demo3:nth-child(4){
left: 40px;
top: 40px;
animation-delay:0.2s;
}
.demo3:nth-child(5){
left: 24px;
top: 47px;
animation-delay:0.4s;
}
.demo3:nth-child(6){
left: 8px;
top: 40px;
animation-delay:0.5s;
}
.demo3:nth-child(7){
left: 2px;
top: 24px;
animation-delay:0.6s;
}
.demo3:nth-child(8){
left: 8px;
top: 8px;
animation-delay:0.7s;
}
@keyframes demo3
{
0%,40%,100% {transform: scale(1);}
20% {transform: scale(3);}
}
@-webkit-keyframes demo3
{
0%,40%,100% {transform: scale(1);}
20% {transform: scale(3);}
}
接下来是第四个动画:
1 <div id="loading5">
2 <div class="demo5"></div>
3 </div>
#loading5 {
width: 20px;
height: 100px;
border-bottom: 1px solid #68b2ce;
}
.demo5 {
width: 20px;
height: 20px;
border-radius: 10px;
background: #68b2ce;
animation: demo5 cubic-bezier(0.5,0.01,0.9,1) 0.6s infinite alternate;
-webkit-animation: demo5 cubic-bezier(0.5,0.01,0.9,1) 0.6s infinite alternate;
}
@keyframes demo5
{
0%{
transform:translateY(0px);
-webkit-transform:translateY(0px);
}
100% {
transform:translateY(80px);
-webkit-transform:translateY(80px);
}
}
@-webkit-keyframes demo5
{
0%{
transform:translateY(0px);
-webkit-transform:translateY(0px);
}
100% {
transform:translateY(80px);
-webkit-transform:translateY(80px);
}
}
css Code
以上就是这几个简单的加载中小动画的内容了。
转载 https://www.cnblogs.com/tangchan/p/7604594.html
览器加载一个js脚本,会在devtools中留下各种痕迹,elements中的script元素,console中的日志,source中的代码,network中的网络请求等
这个比较简单,插入js的时候设置好id,在js中删掉自身就好了
<script id="xxx">
// todo
document.getElementById("xxx").remove();
</script>
对于引用js
<script id="xxx" src="a.js"></script>
// a.js
document.getElementById("xxx").remove()
对于动态加载的js也是一样的
<script>
let e=document.createElement("script");
e.id="xxx";
e.src="a.js";
document.head.appendChild(e);
</script>
// a.js
document.getElementById("xxx").remove()
或者也可以这样
<script>
let e=document.createElement("script");
e.src="a.js";
document.head.appendChild(e);
e.remove();
</script>
虽然看起来很奇怪,但a.js确实能执行,似乎是加载a.js时阻塞了脚本执行,执行完a.js之后再remove
clear就好了
console.clear()
直接引用和动态加载都会在source中出现
<script src="a.js"></script>
<script>
let e=document.createElement("script");
e.src="a.js";
document.head.appendChild(e);
</script>
这样都是不行的,经过测试发现动态插入js代码时不会被记录在source中
<script>
fetch("a.js").then(resp => {
return resp.text()
}).then(text => {
let e = document.createElement("script");
e.innerHTML = text;
document.head.appendChild(e);
})
</script>
这样a.js就不会出现在source里了
常规HTTP/WebSocket都会被记录,无法绕过,但是WebRTC不会,WebRTC可以基于UDP/TCP传输,WebRTC提供createDataChannel API,可以用于传输文本,那么就可以实现network隐藏加载
考虑WebRTC需要传递offer和icecandidate,还是得通过HTTP/WebSocket传输,而且复杂网络环境下还需要使用或部署STUN/TURN服务器,稳定性有待考虑
WebRTC技术可以参考学习我最近看的几篇文章透明日报20200801期
其他的方法我还没有找到,技术不行就社会工程
一个思路是可以伪装成其他流量混过去,比如png
<script>
fetch("a.png").then(resp => {
return resp.text()
}).then(text => {
let e = document.createElement("script");
e.innerHTML = text;
document.head.appendChild(e);
})
</script>
然后在delvtools里也看不出来
另外一个思路是devtools目前只在打开的时候记录network数据,那么只要在devtools关闭的时候加载资源,打开就不加载,这样就不会出现在network里了
新的问题又出现了,如何检测devtools的状态,网上已经有不少公开技巧了
https://github.com/sindresorhus/devtools-detect
https://github.com/AEPKILL/devtools-detector
还可以在哪里找到加载和执行痕迹呢
还有什么方法可以隐藏这些痕迹呢
如果你现在也想学习前端开发技术,在学习前端的过程当中有遇见任何关于学习方法,学习路线,学习效率等方面的问题,你都可以申请加入我的Q群:前114中6649后671还有大牛整理的一套高效率学习路线和教程与您免费分享,还有许多大厂面试真题。希望能够对你们有所帮助。
能大家都知道,js执行会阻塞DOM树的解析和渲染,那么css加载会阻塞DOM树的解析和渲染吗?接下来,我们就一起来分析一下。
那么为什么会出现上面的现象呢?我们从浏览器的渲染过程来解析下。
不同的浏览器使用的内核不同,所以他们的渲染过程也是不一样的。目前主要有两个:
webkit渲染过程
Gecko渲染过程
从上面两个流程图我们可以看出来,浏览器渲染的流程如下:
从流程我们可以看出来
对于浏览器来说,页面加载主要有两个事件,一个是DOMContentLoaded,另一个是onLoad。而onLoad没什么好说的,就是等待页面的所有资源都加载完成才会触发,这些资源包括css、js、图片视频等。
而DOMContentLoaded,顾名思义,就是当页面的内容解析完成后,则触发该事件。那么,正如我们上面讨论过的,css会阻塞Dom渲染和js执行,而js会阻塞Dom解析。那么我们可以做出这样的假设
我们先对第一种情况做测试:
<!DOCTYPE html> <html lang="en"> <head> <title>css阻塞</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script> document.addEventListener('DOMContentLoaded', function() { console.log('DOMContentLoaded'); }) </script> <link href="https://cdn.bootcss.com/bootstrap/4.0.0-alpha.6/css/bootstrap.css" rel="stylesheet"> </head> <body> </body> </html>
实验结果如下图:
从动图我们可以看出来,css还未加载完,就已经触发了DOMContentLoaded事件了。因为css后面没有任何js代码。
接下来我们对第二种情况做测试,很简单,就在css后面加一行代码就行了
<!DOCTYPE html> <html lang="en"> <head> <title>css阻塞</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script> document.addEventListener('DOMContentLoaded', function() { console.log('DOMContentLoaded'); }) </script> <link href="https://cdn.bootcss.com/bootstrap/4.0.0-alpha.6/css/bootstrap.css" rel="stylesheet"> <script> console.log('到我了没'); </script> </head> <body> </body> </html>
实验结果如下图:
我们可以看到,只有在css加载完成后,才会触发DOMContentLoaded事件。因此,我们可以得出结论:
由上所述,我们可以得出以下结论:
因此,为了避免让用户看到长时间的白屏时间,我们应该尽可能的提高css加载速度,比如可以使用以下几种方法:
*请认真填写需求信息,我们会在24小时内与您取得联系。