CSS聚光灯特效

先来看效果

CSS聚光灯特效

CodingStarup

接下来是代码

<h1 data-spotlight="CodingStarup!">CodingStarup</h1>
html{
    font-size: 15px;
}
body{
    background-color: #222;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}
h1{
    color: #333;
    font-family: Helvetica;
    margin: 0;
    padding: 0;
    font-size: 8rem;
    letter-spacing: -0.3rem;
    position: relative;
}

h1::after {
    content: attr(data-spotlight);
    color: transparent;
    position: absolute;
    top: 0;
    left: 0;
    -webkit-clip-path:ellipse(100px 100px at 0% 50%);
    clip-path: ellipse(100px 100px at 0% 50%);
    animation: spotlight 5s infinite;
    -webkit-animation: spotlight 5s infinite;
    background-image: url(https://dogefs.s3.ladydaily.com/~/source/unsplash/photo-1615714464892-b5c2ae1e7371?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80);
    background-size: 150%;
    background-position: center center;
    -webkit-background-clip: text;
    background-clip: text;
}

@keyframes spotlight{
    0%{
        -webkit-clip-path: ellipse(100px 100px at 0% 50%);
        clip-path: ellipse(100px 100px at 0% 50%); 
    }
    50%{
        -webkit-clip-path: ellipse(100px 100px at 100% 50%);
        clip-path: ellipse(100px 100px at 100% 50%); 
    }
    100%{
        -webkit-clip-path: ellipse(100px 100px at 0% 50%);
        clip-path: ellipse(100px 100px at 0% 50%); 
    }
}
© 版权声明
THE END
喜欢就支持一下吧
点赞10赞赏 分享
评论 共2条

请登录后发表评论