<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style type="text/css">
.skt-loading {
pointer-events: none;
}
/* 加载中阻止事件 */
.skt-loading .skeleton {
position: relative;
overflow: hidden;
border: none !important;
border-radius: 5px;
background-color: transparent !important;
background-image: none !important;
}
.skt-loading .skeleton::after {
content: '';
position: absolute;
left: 0;
top: 0;
z-index: 9;
width: 100%;
height: 100%;
background-color: #EBF1F8;
display: block;
}
/* 下面这部分都是自定义的,看需求修改 */
.skt-loading .skeleton::after {
border-radius: 4px;
}
.skt-loading .skeleton::before {
position: absolute;
top: 0;
width: 30%;
height: 100%;
content: "";
background: linear-gradient(to right, rgba(255, 255, 255, 0) 0,
rgba(255, 255, 255, .3) 50%, rgba(255, 255, 255, 0) 100%);
transform: skewX(-45deg);
z-index: 99;
animation: skeleton-ani 1s ease infinite;
display: block;
}
.skt-loading .skeleton.badge::after {
background-color: #F8FAFC;
}
@keyframes skeleton-ani {
/* 骨架屏动画 */
from {
left: -100%;
}
to {
left: 150%;
}
}
</style>
<body>
<div class="skt-loading">
<div style="width: 500px;height: 30px;background-color: antiquewhite;">
你好
</div>
<div style="width: 500px;height: 30px;background-color: antiquewhite;margin: 20px;">
你好
<div style="width: 500px;height: 30px;background-color: antiquewhite;margin: 20px;">
你好
<div style="width: 500px;height: 30px;background-color: antiquewhite;margin: 20px;">
你好
<div style="width: 500px;height: 30px;background-color: antiquewhite;margin: 20px;">
你好
</div>
</div>
</div>
</div>
<div style="width: 100%;height: 100px;background-color: antiquewhite;margin: 20px;">
你好
</div>
<div style="width: fit-content;">
<img src="img/test.jpg" />
</div>
<div>
</div>
</div>
</body>
<script type="text/javascript">
function handleSkeleton(type) {
let child = document.querySelector('.skt-loading').children;
for (var i = 0; i < child.length; i++) {
child.item(i).classList[type]('skeleton')
}
}
handleSkeleton('add')
setTimeout(() => {
handleSkeleton('remove')
document.querySelector('.skt-loading').classList.remove('skt-loading');
}, 3000)
</script>
</html>
使用骨架屏