cssanimationcss-animationsclipclip-path

How to make CSS clip-path show background and only apply animation inside the clipped partion?


I have this CSS. I tried to make it so the clipped circle path expands in a circle, but I want it to not mask the background. I want it to show the background and show the clipped circle also. It should show both the background and the clipped portion.

Once that's done I need it so that the clipped portion has the melt keyframes animation on it so that only the portion inside the clip-path has the melt animation outside there is no animation.

@keyframes expandCircle {
    0% {clip-path: circle(0% at center);}
    100% {clip-path: circle(100% at center);}}
    
@keyframes melt {
    0% {
        filter: blur(20px) contrast(400%) saturate(250%) brightness(125%);
        pointer-events: none;}
    100% {
        filter: none;
        pointer-events: all;}}

#screen-container {
    position: absolute;
    width: 100%;
    height: 100%;
    background-image: url("system/wallpaper/paint.bmp");
    background-repeat: no-repeat;
    background-size: cover;
    background-color: #000000;
    animation: expandCircle 3s forwards;
    clip-path: inset(0 0 0 0 round 8px); /* contain the blur */
    overflow: hidden;
}

#screen-container::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: inherit;
    clip-path: circle(0% at center); 
    animation: melt 2s forwards;
}

Solution

  • You can use the

    ::after pseudo-element to apply the animation only inside the frame, ensuring that #screen-container's clip-path works correctly. Try the following code:

    @keyframes expandCircle {
        0% {
            clip-path: circle(0% at center);
        }
        100% {
            clip-path: circle(100% at center);
        }
    }
    
    @keyframes melt {
        0% {
            filter: blur(20px) contrast(400%) saturate(250%) brightness(125%);
            pointer-events: none;
        }
        100% {
            filter: none;
            pointer-events: all;
        }
    }
    
    #screen-container {
        position: absolute;
        width: 100%;
        height: 100%;
        background-image: url("system/wallpaper/paint.bmp");
        background-repeat: no-repeat;
        background-size: cover;
        background-color: #000000;
    }
    
    #clip-circle {
        position: absolute;
        width: 100%;
        height: 100%;
        clip-path: circle(0% at center);
        animation: expandCircle 3s forwards;
        overflow: hidden;
    }
    
    #clip-circle::after {
        content: "";
        position: absolute;
        width: 100%;
        height: 100%;
        background-image: inherit;
        background-size: cover;
        clip-path: inherit; 
        animation: melt 2s forwards;
    }