css实现纵向扫描

css实现纵向扫描

今天开发需求需要使用扫描来做检测,想着可以用css种animation来实现,就自己写了一下,总体来说也就是控制运动方向,运动速度这些,于是就开始上手了。
在这里插入图片描述

话不多说,直接先附上代码

<!DOCTYPE html>
<html lang="en">
<head>
    <style>
    .div1 {
        width: 500px;
        height: 200px;
        position: relative;
    }
    .img1 {
        width: 500px;
        height: 200px;
        position: relative;
    }

    .div1:after {
        content: '';
        display: block;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background: linear-gradient(270deg, #18cdd3, rgba(0, 177, 255, 0)),
        linear-gradient(90deg, #18cdd3, rgba(0, 177, 255, 0));
        background-size: 0, 0;
        background-position: 0, 100%;
        background-repeat: no-repeat;
        animation: scanAnimation 5s infinite linear;
    }

	@keyframes scanAnimation {
        0% {
            background-size: 0, 0;
            background-position: 0, 100%;
        }
        10% {
            background-size: 30%, 0;
            background-position: 0, 100%;
        }
        50% {
            background-size: 30%, 0;
            background-position: 130%, 100%;
        }
        60% {
            background-size: 30%, 30%;
            background-position: 130%, 100%;
        }
        100% {
            background-size: 30%, 30%;
            background-position: 130%, -30%;
        }
    }
    </style>
</head>
<body>
<div class="div1">
    <img src="./img/111.jpg" class="img1" alt="">
</div>
</body>
</html>

最主要的代码还是这点,让实现动画的主要步骤

.div1:after {
        content: '';
        display: block;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background: linear-gradient(270deg, #18cdd3, rgba(0, 177, 255, 0)),
        linear-gradient(90deg, #18cdd3, rgba(0, 177, 255, 0));
        background-size: 0, 0;
        background-position: 0, 100%;
        background-repeat: no-repeat;
        animation: scanAnimation 5s infinite linear;
    }

至此为止,基本已经结束了,有需要的小伙伴可以参考一下!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值