纯css实现一个拖拉机绘画动画效果

代码语言:html

所属分类:动画

代码描述:纯css实现一个拖拉机绘画动画效果

代码标签: 一个 拖拉机 绘画 动画 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<style>
:root {
        --color-dark: #010101;
        --color-accent: #4072EE;
        --color-light: #FCFFFF;
        --stripes: linear-gradient(90deg, var(--color-dark) 20%, transparent 20%, transparent 40%, var(--color-dark) 40%, var(--color-dark) 60%, transparent 60%, transparent 80%, var(--color-dark) 80%);
       
        --frame-size: 30vw;
        --stripe-width-on-frame: calc(var(--frame-size) * 5 / 24.5);
        --stripe-gap-on-frame: calc(var(--frame-size) / 24.5);
       
        --stripe-gap: calc(var(--stripe-gap-on-frame) * 0.707);
        --stripe-width: calc(var(--stripe-width-on-frame) * 0.707);

        --animation: 30s linear infinite;

        --stripe-x-1: var(--stripe-gap-on-frame);
        --stripe-x-2: calc(var(--stripe-gap-on-frame) * 2 + var(--stripe-width-on-frame));
        --stripe-x-3: calc(var(--stripe-gap-on-frame) * 3 + var(--stripe-width-on-frame) * 2);
        --stripe-x-4: calc(var(--stripe-gap-on-frame) * 4 + var(--stripe-width-on-frame) * 3);

        --stripe-height-1: calc((var(--stripe-gap-on-frame) + var(--stripe-width-on-frame)) / 0.707);
        --stripe-height-2: calc((var(--stripe-gap-on-frame) * 2 + var(--stripe-width-on-frame) * 2) / 0.707);
        --stripe-height-3: calc((var(--stripe-gap-on-frame) * 3 + var(--stripe-width-on-frame) * 3) / 0.707);
        --stripe-height-4: calc((var(--stripe-gap-on-frame) * 4 + var(--stripe-width-on-frame) * 4) / 0.707);
}

html, body {
        height: 100vh; width: 100vw;
        min-height: 60vw;
        padding: 0; margin: 0;
}

body {
        display: flex;
        justify-content: center;
        align-items: center;
        background: linear-gradient(rgba(0,0,0,0.06), rgba(0,0,0,0.14));
}

body *, body *:before, body *:after {
                content: '';
                position: absolute;
        }

.frame {
        position: relative;
        width: var(--frame-size);
        height: var(--frame-size);
        border: 3.2vw solid rgba(255,255,255,0.2);
        box-shadow: 0 11vw 7.5vw rgba(0, 32, 51, 0.08),
                                                        0 1.5vw 4vw rgba(0, 32, 51, 0.05),
                                                        0 4vw 2vw -3vw rgba(0, 32, 51, 0.04),
                                                        0 2vw 1vw -1vw rgba(0, 32, 51, 0.04),
                                                        0 0.6vw 0.5vw rgba(0, 32, 51, 0.03),
                                                        0 -0.2vw 0.5vw rgba(0, 32, 51, 0.03);
}

.frame::before {
                left: -2vw;
    right: -2vw;
    top: -2vw;
    bottom: -2vw;
    border-top: 2vw solid rgba(0,0,0,0.09);
    border-left: 2vw solid rgba(0,0,0,0.05);
    border-right: 2vw solid rgba(0,0,0,0.04);
    border-bottom: 2vw solid rgba(255,255,255,0.3);
                box-shadow: inset 0 0.2vw 0 rgba(0,0,0,0.2),
                                                                inset 0.2vw 0 0 rgba(0,0,0,0.08),
                                                                inset -0.2vw 0 0 rgba(0,0,0,0.08),
                                                                inset 0 -0.2vw 0 rgba(255,255,255,0.2);
        }

.frame::after {
    top: -3.2vw;
    bottom: -3.2vw;
    right: -3.2vw;
    left: -3.2vw;
    border-top: 0.1vw solid rgba(255,255,255,0.4);
    border-left: 0.1vw solid rgba(127,127,127,0.2);
    border-right: 0.1vw solid rgba(127,127,127,0.2);
    border-bottom: 0.1vw solid rgba(0,0,0,0.3);
        }

.picture {
        width: 100%; height: 100%;
        overflow: hidden;
        box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1), inset 0 1px 1px rgba(0, 0, 0, 0.1);
}

.stripe {
        --height: calc((var(--stripe-gap-on-frame) * var(--index) + var(--stripe-width-on-frame) * var(--index)) / 0.707);
        width: var(--stripe-width);
        height: var(--height);
       
        transform: rotate(45deg);
}
.stripe_1 { --index: 1; }
.stripe_2 { --index: 2; }
.stripe_3 { --index: 3; }
.stripe_4 { --index: 4; }
.stripe_5 { --index: 4; }
.stripe_6 { --index: 3; }
.stripe_7 { --index: 2; }
.stripe_8 { --index: 1; }

.stripe:nth-child(-n+4) {
        top: 0;
        left: calc(var(--stripe-gap-on-frame) * var(--index) + var(--stripe-width-on-frame) * (var(--index) - 1));
        transform-origin: top left;
}

.stripe:nth-child(-n+4)::before { top: calc(var(--stripe-width) * -1); }
.stripe:nth-child(n+5) {
        bottom: 0;
        right: calc(var(--stripe-gap-on-frame) * var(--index) + var(--stripe-width-on-frame) * (var(--index) - 1));
        transform-origin: bottom right;
}
.stripe:nth-child(n+5)::before { bottom: calc(var(--stripe-width) * -1); }

.stripe::before {
        width: 100%;
        height: 100%;
        background: var(--stripes);
}
.stripe_1::before {
        transform-origin: top center;
        animation: stripe1Anim var(--animation);
}
.stripe_2::before {
        transform-origin: bottom center;
        animation: stripe2Anim var(--animation);
}
.stripe_3::before {
        transform-origin: top center;
        animation: stripe3Anim var(--animation);
}
.stripe_4::before {
        transform-origin: bottom center;
        animation: stripe4Anim var(--animation);
}
.stripe_5::before {
        transform-origin: top center;
        animation: stripe5Anim var(--animation);
}
.stripe_6::before {
        transform-origin: bottom center;
        animation: stripe6Anim var(--animation);
}
.stripe_7::before {
        transform-origin: top center;
        animation: stripe7Anim var(--animation);
}
.stripe_8::before {
        transform-origin: bottom center;
        animation: stripe8Anim var(--animation);
}

@keyframes stripe1Anim {
        0% { transform: scaleY(1.37) translateY(calc(var(--stripe-height-1) * -1 + var(--stripe-width) * -2.78)); }
        9.4%, 100% { transform: translateY(0) scaleY(1.37); }

        99% { opacity: 1; }
        100% { opacity: 0; }
}
@keyframes stripe2Anim {
        0%, 9.4% { transform: scaleY(1.12) translateY(calc(var(--stripe-height-2) + var(--stripe-width) * 3.9)); }
        21.2%, 100% { transform: scaleY(1.12); }

        99% { opacity: 1; }
        100% { opacity: 0; }
}
@keyframes stripe3Anim {
        0%, 21.2% { transform: scaleY(1.13) translateY(calc(var(--stripe-height-3) * -1 + var(--stripe-width) * -3.8)); }
        36.9%, 100% { transform: translateY(0) scaleY(1.13); }

        99% { opacity: 1; }
        100% { opacity: 0; }
}
@keyframes stripe4Anim {
        0%, 36.9% { transform: scaleY(1.03) translateY(calc(var(--stripe-height-4) + var(--stripe-width) * 2.7)); }
        53.7%, 100% { transform: scaleY(1.03); }

        99% { opacity: 1; }
        100% { opacity: 0; }
}
@keyframes stripe5Anim {
        0%, 53.7% { transform: translateY(calc(var(--stripe-height-4) * -1 + var(--stripe-width) * -2.81)); }
        70%, 100% { transform: translateY(0); }

        99% { opacity: 1; }
        100% { opacity: 0; }
}
@keyframes stripe6Anim {
        0%, 70% { transform: translateY(calc(var(--stripe-height-3) + var(--stripe-width) * 2.81)); }
        83.2%, 100% { transform: translateY(0); }

        99% { opacity: 1; }
        100% { opacity: 0; }
}
@keyframes stripe7Anim {
        0%, 83.2% { transform: translateY(calc(var(--stripe-height-2) * -1 + var(--stripe-width) * -2.81)); }
        93.1%, 100% { transform: translateY(0); }

        99% { opacity: 1; }
        100% { opacity: 0; }
}
@keyframes stripe8Anim {
                0%, 93.1% { transform: translateY(calc(var(--stripe-height-1) + var(--stripe-width) * 2.81)); }
                100% { transform: translateY(0); }

                99% { opacity: 1; }
                100% { opacity: 0; }
        }


.tractor {
        width: var(--stripe-width);
        height: calc(var(--stripe-width) * 0.54);
        background: var(--color-dark);
}


.tractor::before {
                left: calc(var(--stripe-width) * -0.05);
                top: calc(var(--stripe-width) * 0.94);
                width: calc(var(--stripe-width) * 1.28);
                height: calc(var(--stripe-width) * 1.75);
                background: var(--color-dark);
                border-radius: calc(var(--stripe-width) * 0.1);
        }


.tractor::after {
                right: calc(var(--stripe-width) * -0.18);
                top: calc(var(--stripe-width) * 0.98);
                width: calc(var(--stripe-width) * 0.08);
                height: calc(var(--stripe-width) * 0.55);
                background: var(--color-accent);
                border-radius: 100%;
                box-shadow: 0 calc(var(--stripe-width) * 1.1) var(--color-accent);
        }


.tractor > div:nth-child(1) {
                left: calc(var(--stripe-width) * 0.56);
                top: calc(var(--stripe-width) * 2);
                width: calc(var(--stripe-width) * 0.4);
                height: calc(var(--stripe-width) * 1.1);
                background: linear-gradient(130deg, var(--color-dark) 77%, transparent 10%);
        }


.tractor > div:nth-child(1)::before {
                        left: calc(var(--stripe-width) * -0.35);
                        top: calc(var(--stripe-width) * -1.13);
                        width: calc(var(--stripe-width) * 0.6);
                        height: calc(var(--stripe-width) * 1.36);
                        background: var(--color-accent);
                        border-radius: calc(var(--stri.........完整代码请登录后点击上方下载按钮下载查看

网友评论0