css实现小仓鼠在圈子里跑动发电动画效果代码

代码语言:html

所属分类:动画

代码描述:css实现小仓鼠在圈子里跑动发电动画效果代码

代码标签: css 仓鼠 笼子 跑动 动画

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

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">



    <style>
        * {
        	border: 0;
        	box-sizing: border-box;
        	margin: 0;
        	padding: 0;
        }
        :root {
        	--bg: hsl(90,90%,20%);
        	--fg: hsl(223,10%,10%);
        	font-size: calc(16px + (24 - 16) * (100vw - 320px) / (1280 - 320));
        }
        body {
        	background: var(--bg);
        	color: var(--fg);
        	font: 1em/1.5 sans-serif;
        	height: 100vh;
        	display: grid;
        	place-items: center;
        }
        .wheel-and-hamster {
        	--dur: 1s;
        	position: relative;
        	width: 12em;
        	height: 12em;
        }
        .wheel,
        .hamster,
        .hamster div,
        .spoke {
        	position: absolute;
        }
        .wheel,
        .spoke {
        	border-radius: 50%;
        	top: 0;
        	left: 0;
        	width: 100%;
        	height: 100%;
        }
        .wheel {
        	background: radial-gradient(100% 100% at center,hsla(0,0%,60%,0) 47.8%,hsl(0,0%,60%) 48%);
        	z-index: 2;
        }
        .hamster {
        	animation: hamster var(--dur) ease-in-out infinite;
        	top: 50%;
        	left: calc(50% - 3.5em);
        	width: 7em;
        	height: 3.75em;
        	transform: rotate(4deg) translate(-0.8em,1.85em);
        	transform-origin: 50% 0;
        	z-index: 1;
        }
        .hamster__head {
        	animation: hamsterHead var(--dur) ease-in-out infinite;
        	background: hsl(30,90%,55%);
        	border-radius: 70% 30% 0 100% / 40% 25% 25% 60%;
        	box-shadow:
        		0 -0.25em 0 hsl(30,90%,80%) inset,
        		0.75em -1.55em 0 hsl(30,90%,90%) inset;
        	top: 0;
        	left: -2em;
        	width: 2.75em;
        	height: 2.5em;
        	transform-origin: 100% 50%;
        }
        .hamster__ear {
        	animation: hamsterEar var(--dur) ease-in-out infinite;
        	background: hsl(0,90%,85%);
        	border-radius: 50%;
        	box-shadow: -0.25em 0 hsl(30,90%,55%) inset;
        	top: -0.25em;
        	right: -0.25em;
        	width: 0.75em;
        	height: 0.75em;
        	transform-origin: 50% 75%;
        }
        .hamster__eye {
        	animation: hamsterEye var(--dur) linear infinite;
        	background-color: hsl(0,0%,0%);
        	border-radius: 50%;
        	top: 0.375em;
        	left: 1.25em;
        	width: 0.5em;
        	height: 0.5em;
        }
        .hamster__nose {
        	background: hsl(0,90%,75%);
        	border-radius: 35% 65% 85% 15% / 70% 50% 50% 30%;
        	top: 0.75em;
        	left: 0;
        	width: 0.2em;
        	height: 0.25em;
        }
        .hamster__body {
        	animation: hamsterBody var(--dur) ease-in-out infinite;
        	background: hsl(30,90%,90%);
        	border-radius: 50% 30% 50% 30% / 15% 60% 40% 40%;
        	box-shadow:
        		0.1em 0.75em 0 hsl(30,90%,55%) inset,
        		0.15em -0.5em 0 hsl(30,90%,80%) inset;
        	top: 0.25em;
        	left: 2em;
        	width: 4.5em;
        	height: 3em;
        	transform-origin: 17% 50%;
        	transform-style: preserve-3d;
        }
        .hamster__limb--fr,
        .hamster__limb--fl {
        	clip-path: polygon(0 0,100% 0,70% 80%,60% 100%,0% 100%,40% 80%);
        	top: 2em;
        	left: 0.5em;
        	width: 1em;
        	height: 1.5em;
        	transform-origin: 50% 0;
        }
        .hamster__limb--fr {
        	animation: hamsterFRLimb var(--dur) linear infinite;
        	background: linear-gradient(hsl(30,90%,80%) 80%,hsl(0,90%,75%) 80%);
        	transform: rotate(15deg) translateZ(-1px);
        }
        .hamster__limb--fl {
        	animation: hamsterFLLimb var(--dur) linear infinite;
        	background: linear-gradient(hsl(30,90%,90%) 80%,hsl(0,90%,85%) 80%);
        	transform: rotate(15deg);
        }
        .hamster__limb--br,
        .hamster__limb--bl {
        	border-radius: 0.75em 0.75em 0 0;
        	clip-path: polygon(0 0,100% 0,100% 30%,70% 90%,70% 100%,30% 100%,40% 90%,0% 30%);
        	top: 1em;
        	left: 2.8em;
        	width: 1.5em;
        	height: 2.5em;
        	transform-origin: 50%.........完整代码请登录后点击上方下载按钮下载查看

网友评论0