骑自行车(Riding)

骑自行车-动画(Riding)


更多有趣示例 尽在 知屋安砖社区

示例

在这里插入图片描述

HTML

div.main
    div.human
        div.human__legs
            div.human__b
            div.human__leg.human__leg--left
            div.human__leg.human__leg--right
                
        div.human__arms
            div.human__t
            div.human__arm.human__arm--left
            div.human__forearm.human__forearm--left
                
            div.human__arm.human__arm--right
            div.human__forearm.human__forearm--right
                
                
        div.human__head
            div.human__helmet
            div.human__face
                div.human__ear.human__ear--left
                div.human__ear.human__ear--right
                
    div.bike
        div.bike__handle
        div.bike__seat
        div.bike__wheel
            
    div.city
        div.city__b1
        div.city__b2
        div.city__b3
            
    div.trees
        div.tree.tree--l1
        div.tree.tree--l2
        div.tree.tree--l3
        div.tree.tree--r1
        div.tree.tree--r2
        div.tree.tree--r3
        
    div.clouds 
        div.cloud                            
        div.cloud

CSS

/* Variables */
$black-1: #5F2E3C;
$white-1: #FFFFFF;
$green-1: #00B4BC;
$green-2: #008496;
$skin-1: #FFA87F;
$skin-2: #FF8A6F;
$purple-1: #7C5DA8;
$purple-2: #6A4A8D;
$purple-3: #614184;
$purple-4: #4E3480;


$animation: .4s infinite linear alternate;


/* Reset */
*, *::after, *::before {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}
/* Generic */
body{
    width: 100%;
    height: 100vh;
    min-width: 800px;
    min-height: 600px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: $purple-2;
}
.main{
    display: flex;
    justify-content: center;
    position: relative;
    width: 800px;
    height: 600px;
    overflow: hidden;
}
/**/
.human{
    display: flex;
    justify-content: center;
    position: absolute;
    bottom: 65px;
    width: 160px;
    height: 380px;


    &__legs{
        position: absolute;
        bottom: 50px;
        width: 80px;
        height: 270px;
        animation: legs $animation;
    }
        &__b{
            position: absolute;
            top: 5px;
            width: 80px;
            height: 50px;
            border-radius: 20px;
            background-image: linear-gradient(to bottom, darken($green-2, 3), $green-2);
            z-index: 10;
        }
        &__leg{
            display: flex;
            justify-content: center;
            position: absolute;
            top: 0;
            width: 20px;
            height: 235px;
            background-image: linear-gradient(
                to bottom,
                $green-2 0%,
                $green-2 40%,
                $skin-2 40%,
                $skin-2 70%,
                $green-1 70%,
                $green-1 72%,
                $white-1 72%,
                $white-1 74%,
                $green-1 74%,
                $green-1 100%
            );
            &::before{
                content: '';
                position: absolute;
                bottom: 0;
                width: 25px;
                height: 10px;
                background-color: $black-1;
            }
            &::after{
                content: '';
                position: absolute;
                bottom: 0;
                border-top: 10px solid $white-1;
                border-left: 10px solid $white-1;
                border-right: 10px solid transparent;
                border-bottom: 10px solid transparent;
                border-radius: 50%;
                transform: rotateZ(45deg);
            }
            &--left{
                left: 0;
                animation:  leg $animation;
            }
            &--right{
                right: 0;
                animation:  leg $animation .4s;
            }
        }
    /* ========== */
    &__arms{
        display: flex;
        justify-content: center;
        position: absolute;
        top: 30px;
        width: 150px;
        height: 180px;
    }
        &__t{
            position: absolute;
            top: 3px;
            width: 80px;
            height: 60px;
            border-radius: 25px;
            overflow: hidden;
            background-color: $green-2;
            border-top: 8px solid $green-1;
            box-shadow: 0 0 4px rgba($black-1, .3);


            animation: human-t $animation;


            &::before,
            &::after{
                content: '';
                position: absolute;
                top: 30%;
                left: -60%;
                height: 80px;
                width: 80px;
                border: 10px solid $white-1;
                border-radius: 50%;
            }


            &::after{ left: 60%; }
        }
        &__arm{
            position: absolute;
            bottom: 20px;
            width: 20px;
            height: 86px;
            background-color: $skin-1;
            border-bottom: 25px solid $green-1;
            border-radius: 5px;
            z-index: -2;
            &--left{
                left: 0;
                animation: arm-l $animation;
            }
            &--right{
                right:  0;
                animation: arm-r $animation;
            }
        }
        &__forearm{
            position: absolute;
            width: 20px;
            height: 90px;
            background-color: $green-2;
            border-radius: 10px;
            z-index: -1;
            &--left{
                transform: rotateZ(35deg);
                left: 20px;
                animation: forearm-l $animation;
            }
            &--right{
                transform: rotateZ(-35deg);
                right: 20px;
                animation: forearm-r $animation;
            }
        }
    /* ========== */
    &__head{
        display: flex;
        justify-content: center;
        position: absolute;
        width: 80px;
        height: 90px;


        animation: head $animation;
    }
        &__helmet{
            position: absolute;
            top: -5px;
            width: 70px;
            height: 50px;
            background-image: linear-gradient(to bottom, $green-1 50%, $green-2 50%);
            border-radius: 50%;


            &::before,
            &::after{
                content: '';
                position: absolute;
                bottom: 30px;
                width: 10px;
                height: 5px;
                background-color: $green-2;
                z-index: 1;
                animation: glasses $animation;
            }
            &::before{
                left: 10px;
                border-bottom-left-radius: 10px;
            }
            &::after{
                right: 10px;
                border-bottom-right-radius: 10px;
            }
        }
        &__face{
            position: absolute;
            top: 25px;
            width: 45px;
            height: 60px;
            border-bottom-left-radius: 50%;
            border-bottom-right-radius: 50%;
            background-color: $skin-1;
            border-top: 5px solid $skin-2;
            border-bottom: 5px solid $black-1;


            &::before,
            &::after{
                content: '';
                position: absolute;
                bottom: 30px;
                width: 22px;
                height: 12px;
                background-color: $black-1;
                z-index: 1;
                animation: glasses $animation;
            }
            &::before{
                left: -5px;
                border-bottom-left-radius: 10px;
            }
            &::after{
                right: -5px;
                border-bottom-right-radius: 10px;
            }
        }
        &__ear{
            position: absolute;
            bottom: 25px;
            border-top: 6px solid $skin-2;
            border-left: 6px solid $skin-2;
            border-bottom: 6px solid transparent;
            border-right: 6px solid transparent;
            border-radius: 50%;


            &--left{
                transform: rotateZ(-45deg);
                left: -6px;
            }
            &--right{
                transform: rotateZ(135deg);
                right: -6px;
            }
        }
}
/* ========== */
.bike{
    display: flex;
    justify-content: center;
    position: absolute;
    bottom: 65px;
    width: 140px;
    height: 225px;
    animation: bike $animation;


    &__handle{
        position: absolute;
        top: 10px;
        width: 140px;
        height: 50px;
        border: 10px solid $black-1;
        border-bottom: 10px solid transparent;
        border-radius: 20px;


        &::before,
        &::after{
            content: '';
            position: absolute;
            bottom: 5px;
            width: 25px;
            height: 25px;
            z-index: 1000;
            border-radius: 5px;
            border-bottom: 10px solid $skin-1;
            border-bottom-left-radius: 10px;
            border-top-right-radius: 10px;
        }
        &::before{
            left: -15px;
            border-left: 10px solid $green-1;
            border-right: 10px solid $skin-1;
        }
        &::after{
            right: -15px;
            border-left: 10px solid $skin-1;
            border-right: 10px solid $green-1;
        }
    }
    &__wheel{
        display: flex;
        justify-content: center;
        position: absolute;
        bottom: 0;
        width: 20px;
        height: 160px;
        border-radius: 10px;
        background-color: $black-1;


        &::before{
            content: '';
            position: absolute;
            top: calc(50% - 7px);
            width:  30px;
            height: 14px;
            z-index: -1;
            border-radius: 20px;
            background-color: $green-1;
        }
    }
    &__seat{
        display: flex;
        justify-content: center;
        position: absolute;
        width: 15px;
        height: 100px;
        border-radius: 10px;
        background-color: $purple-1;
        &::before{
            content: '';
            position: absolute;
            top: -5px;
            width:  30px;
            height: 25px;
            z-index: -1;
            border-radius: 20px;
            background-image: linear-gradient(to bottom, $black-1 50%, $purple-2 50%);
        }
    }
}
.city{
    position: absolute;
    bottom: 65px;
    width: 300px;
    height: 30px;
    background-color: $purple-3;
    z-index: -1;


    &::before{
        content: '';
        position: absolute;
        bottom: 30px;
        right: 0;
        width: 250px;
        height: 10px;
        background-color: $purple-3;
    }
    &__b1,
    &__b2,
    &__b3{
        position: absolute;
        bottom: 0;
        left: 50px;
        width: 40px;
        height: 70px;
        background-color: $purple-3;
    }
    &__b2{
        left: 100px;
        height: 60px;
    }
    &__b3{
        left: 200px;
        height: 80px;
    }
}
.cloud{
    position: absolute;
    top: 200px;
    left: 60px;
    display: flex;
    justify-content: center;
    width: 85px;
    height: 20px;
    z-index: -1;


    &:nth-of-type(2){
        left: 80%;
        top: 100px;
    }
    &::before,
    &::after{
        content: '';
        position: absolute;
        border-radius: 50%;
        border-top: 20px solid $purple-1;
        border-left: 20px solid $purple-1;
        border-bottom: 20px solid transparent;
        border-right: 20px solid transparent;
        transform: rotateZ(45deg);
    }
    &::after{
        margin-left: -20px;
        margin-top: 5px;
        border-top: 15px solid $purple-1;
        border-left: 15px solid $purple-1;
        border-bottom: 15px solid transparent;
        border-right: 15px solid transparent;
    }
}


.tree{
    display: flex;
    justify-content: center;
    position: absolute;
    bottom: 265px;
    left: 0;
    width: 100px;
    height: 100px;
    background-color: $purple-3;
    border-radius: 50%;


    &--l1{ animation: tree-l 3s linear infinite; }
    &--l2{ animation: tree-l 3s linear infinite 1s; }
    &--l3{ animation: tree-l 3s linear infinite 2s; }
    &--r1{ animation: tree-r 3s linear infinite; }
    &--r2{ animation: tree-r 3s linear infinite 1s;}
    &--r3{ animation: tree-r 3s linear infinite 2s; }
    &::before{
        content: '';
        top: 50px;
        position: absolute;
        width: 5px;
        height: 250px;
        background-color: $purple-4;
    }
    &::after{
        content: '';
        top: 125px;
        left: 55px;
        position: absolute;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background-color: $purple-3;
    }
}
/* ========== */




@keyframes human-t {
    0%{ transform: rotateZ(-7deg) translateX(-3px); }
    100%{ transform: rotateZ(7deg) translateX(3px); }
}
@keyframes head {
    0%{ transform: rotateZ(-10deg) translateX(-3px) translateY(3px); }
    50%{ transform: rotateZ(0deg) translateX(0px) translateY(0); }
    100%{ transform: rotateZ(10deg) translateX(3px) translateY(3px); }
}
@keyframes face {
    0%{ transform: translateX(-2px); }
    100%{ transform:translateX(2px);}
}
@keyframes glasses {
    0%{ transform: translateX(-3px); }
    100%{ transform:translateX(3px); }
}
@keyframes arm-l {
    0%{
        left: -10px;
        bottom: 15px;
        transform: rotateZ(-5deg) ;
        transform: top center;
    }
    100%{
        left: 11px;
        bottom: 20px;
        transform: rotateZ(5deg) ;
        transform: top center;


    }
}
@keyframes forearm-l {
    0%{
        top: 0;
        left: 18px;
        height: 110px;
        transform: rotateZ(45deg);
    }
    100%{
        top: 8px;
        left: 25px;
        height: 80px;
        transform: rotateZ(25deg);
    }
}
@keyframes arm-r {
    0%{
        right: 11px;
        bottom: 18px;
        transform: rotateZ(-5deg) ;
        transform: top center;
    }
    100%{
        right: -10px;
        bottom: 13px;
        transform: rotateZ(5deg) ;
        transform: top center;
    }
}
@keyframes forearm-r {
    0%{
        top: 8px;
        right: 25px;
        height: 80px;
        transform: rotateZ(-25deg);
    }
    100%{
        top: 0;
        right: 18px;
        height: 110px;
        transform: rotateZ(-45deg);
    }
}
@keyframes legs {
    0%{ transform: rotateZ(-3deg); }
    100%{ transform: rotateZ(3deg); }
}
@keyframes leg {
    0%{ top: 0; }
    100%{ top: 40px; }
}
@keyframes bike {
    0%{
        transform: rotateZ(-2.6deg);
        transform-origin: bottom center;
    }
    100%{
        transform: rotateZ(2.6deg);
        transform-origin: bottom center;
    }
}
@keyframes tree-l {
    0%{
        bottom: 265px;
        transform: translateX(-100px) scale(1) ;
        transform-origin: bottom center;
        opacity: 1;
    }
    100%{
        bottom: 85px;
        transform: translateX(200px) scale(.1) ;
        transform-origin: bottom center;
        opacity: .3;
    }
}
@keyframes tree-r {
    0%{
        bottom: 265px;
        transform: translateX(800px) scale(1) ;
        transform-origin: bottom center;
        opacity: 1;
    }
    100%{
        bottom: 85px;
        transform: translateX(500px) scale(.1) ;
        transform-origin: bottom center;
        opacity: .3;
    }
}

JS

/*
Designed by: Valentin Kirilov
Original image: https://dribbble.com/shots/2859750-Tour-de-France
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值