纯CSS实现猫咪

效果图

在这里插入图片描述

index

import React from 'react'
import styles from './style.less'
const index = () =>
{
    return (
        <div>
            <div className={styles.container} >
                <div className={styles.wrapper}>
                    <div className={styles.sun}></div>
                    <div className={styles.cloud}></div>
                    <div className={styles.cat}>
                        <div className={`${styles.eye} ${styles.left}`} ><div className={styles.eye_hide} ></div></div>
                        <div className={`${styles.eye} ${styles.right}`} ><div className={styles.eye_hide} ></div></div>
                        <div className={styles.nose}></div>
                        <div className={styles.mouth}></div>
                    </div>
                </div>
            </div>
        </div >
    )
}

export default index

CSS

@cat: rgb(180, 0, 54); // 定义小猫颜色变量

// 定义变量
:root {
  --bgColor: rgb(81, 136, 168);
  --eyeHideTop: 0px;
  --cloudLeft: 45%;
  --mouthRadius: 10px 10px 0 0;
}

// 容器
.container {
  width: 100%;
  height: 100vh;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: repeating-linear-gradient(0deg, hsla(340, 87%, 75%, 0.2) 0px, hsla(340, 87%, 75%, 0.2) 30px, transparent 30px, transparent 60px), repeating-linear-gradient(90deg, hsla(340, 87%, 75%, 0.2) 0px, hsla(340, 87%, 75%, 0.2) 30px, transparent 30px, transparent 60px), linear-gradient(90deg, rgb(255, 255, 255), rgb(255, 255, 255));
}

// 界面
.wrapper {
  width: 320px;
  height: 320px;
  border-radius: 50%;
  border: 10px solid white;
  position: relative;
  overflow: hidden;
  background-color: var(--bgColor);
  transition: background-color 1s linear;
  cursor: url('https://blog-static.cnblogs.com/files/lucas--liu/cat6.ico'), default;

  &:hover {
    --bgColor: rgb(178, 222, 247);
    --eyeHideTop: -20px;
    --cloudLeft: 100%;
    --mouthRadius: 0 0 10px 10px;
  }
}

// 太阳
.sun {
  width: 50px;
  height: 50px;
  position: absolute;
  background-color: rgb(255, 229, 142);
  border: 7px solid rgb(253, 215, 91);
  border-radius: 50%;
  left: 55%;
  top: 14%;
  box-shadow: 0 0 6px rgb(255, 241, 48);
}

// 云朵
.cloud {
  width: 100px;
  height: 36px;
  background-color: white;
  position: absolute;
  transition: left .6s linear;
  left: var(--cloudLeft);
  top: 23%;
  border-radius: 36px;
  animation: bouncy 2s ease-in-out infinite;

  &::before {
    content: '';
    width: 50px;
    height: 50px;
    background-color: white;
    border-radius: 50%;
    position: absolute;
    top: -23px;
    left: 18px;
  }

  &::after {
    content: '';
    width: 26px;
    height: 26px;
    background-color: white;
    border-radius: 50%;
    position: absolute;
    top: -16px;
    left: 56px;
  }
}

// 云朵呼吸动画
@keyframes bouncy {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }

  100% {
    transform: scale(1);
  }
}

// 猫咪
.cat {
  width: 180px;
  height: 160px;
  background-color: @cat;
  position: absolute;
  bottom: -20px;
  left: 50%;
  margin-left: -90px;
  animation: wait 5s ease-in-out infinite;

  &::after,
  &::before {
    content: '';
    display: block;
    border-style: solid;
    border-width: 20px 30px;
    position: absolute;
    top: -30px;
  }

  &::after {
    right: 0;
    border-color: transparent @cat @cat transparent;
  }

  &::before {
    left: 0;
    border-color: transparent transparent @cat @cat;
  }

  .eye {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    position: absolute;
    top: 30px;
    background: white;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;

    .eye_hide {
      height: 20px;
      position: absolute;
      top: var(--eyeHideTop);
      left: -2px;
      right: -2px;
      background-color: @cat;
      transition: top .5s ease-in-out;
      z-index: 2;
    }

    &::before {
      content: "";
      height: 36px;
      width: 36px;
      background-color: black;
      border-radius: 50%;
    }

    &::after {
      content: "";
      width: 24px;
      height: 24px;
      background-color: white;
      border-radius: 50%;
      position: absolute;
      right: 0px;
      top: 0px;
    }

    &.left {
      left: 24px;
    }

    &.right {
      right: 24px;
    }
  }

  .nose {
    width: 0;
    height: 0;
    border-top: 7px solid rgb(248, 226, 226);
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    position: absolute;
    left: 50%;
    margin-left: -7px;
    top: 70px;
  }

  .mouth {
    width: 26px;
    height: 20px;
    background-color: rgb(255, 217, 217);
    position: absolute;
    top: 85px;
    left: 50%;
    margin-left: -13px;
    border-radius: var(--mouthRadius);
    transition: border-radius .2s linear;
    overflow: hidden;

    &::after,
    &::before {
      content: "";
      position: absolute;
      display: block;
      top: 0;
      border-top: 7px solid white;
      border-left: 2px solid transparent;
      border-right: 2px solid transparent;
    }

    &::after {
      right: 5px;
    }

    &::before {
      left: 5px;
    }
  }
}

@keyframes wait {
  0% {
    bottom: -25px;
  }

  50% {
    bottom: -30px;
  }

  100% {
    bottom: -20px;
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

臧小川

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值