手写骨架屏

手写骨架屏

在公共样式里书写如下css

/* Skeletons效果 */
.dom_loading {
    position: relative;
    display: block;
    overflow: hidden;
    width: 100%;
    min-height: 16px;
    border-radius: 4px;
}
.dom_loading::after {
    display: block;
    content: "";
    position: absolute;
    top: -30%;
    width: 20px;
    height: 200%;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, rgb(202, 202, 202), transparent);
    animation-duration: 2s;
    animation-delay: 0.3s;
    animation-iteration-count: infinite;
    animation: loading 2s linear infinite;
    z-index: 10;
}
.dom_loading::before { /* 这块样式是覆盖内容的,如果不需要覆盖内容可以不要这个伪元素 */
    display: block;
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    min-height: 16px;
    background-color: #b7b7b7;
    border-radius: 4px;
    z-index: 9;
}
@keyframes loading {
    /* 骨架屏动画 */
    from {
        -webkit-transform: translateX(-100px) rotateZ(45deg);
        transform: translateX(-100px) rotateZ(45deg);
    }
    to {
        -webkit-transform: translateX(1000px) rotateZ(45deg);
        transform: translateX(1000px) rotateZ(45deg);
    }
}

然后在需要骨架屏的地方根据数据拿到之前,添加‘dom_loading’ 的 class,该元素必须具有真实的宽高

最后效果:

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值