svg实现手指不耐烦敲击动画效果代码
代码语言:html
所属分类:动画
代码描述:svg实现手指不耐烦敲击动画效果代码
下面为部分代码预览,完整代码请点击下载或在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 { --hue: 223; --sat: 10%; --gray0: hsl(0,0%,100%); --gray1: hsl(var(--hue),var(--sat),90%); --gray2: hsl(var(--hue),var(--sat),80%); --gray3: hsl(var(--hue),var(--sat),70%); --gray4: hsl(var(--hue),var(--sat),60%); --gray5: hsl(var(--hue),var(--sat),50%); --gray6: hsl(var(--hue),var(--sat),40%); --gray7: hsl(var(--hue),var(--sat),30%); --gray8: hsl(var(--hue),var(--sat),20%); --gray9: hsl(var(--hue),var(--sat),10%); --trans-dur: 0.3s; font-size: clamp(1rem,0.95rem + 0.25vw,1.25rem); } body { background-color: var(--gray0); color: var(--gray9); display: flex; font: 1em/1.5 sans-serif; height: 100vh; transition: background-color var(--trans-dur), color var(--trans-dur); } .hand { --anim-dur: 1s; --anim-timing: cubic-bezier(0.65,0,0.35,1); display: block; margin: auto; width: 9.6em; height: auto; } .hand__finger, .hand__finger-inner { animation-duration: var(--anim-dur); animation-timing-function: var(--anim-timing); animation-iteration-count: infinite; } .hand__finger-inner { animation-name: finger-inner; fill: var(--gray4); } .hand__finger--pinky { animation-name: pinky; } .hand__finger--pinky, .hand__finger--pinky .hand__finger-inner { animation-delay: calc(var(--anim-dur) * 0.16); } .hand__finger--ring { animation-name: ring; } .hand__finger--ring, .hand__finger--ring .hand__finger-inner { animation-delay: calc(var(--anim-dur) * 0.12); } .hand__finger--middle .hand__finger-inner { animation-delay: calc(var(--anim-dur) * 0.08); } .hand__finger--index { animation-name: index; } .hand__finger--index, .hand__finger--index .hand__finger-inner { animation-delay: calc(var(--anim-dur) * 0.04); } .hand__finger--thumb .hand__finger-inner { animation-name: thumb-inner; } .hand__finger-inner, .hand__nail, .hand__skin { transition: fill var(--trans-dur); } .hand__nail { fill: var(--gray0); } .hand__skin { fill: var(--gray2); } /* Dark theme */ @media (prefers-color-scheme: dark) { body { background-color: var(--gray9); color: var(--gray1); } .hand__finger-inner { fill: var(--gray9); } .hand__nail { fill: var(--gray5); } .hand__skin { fill: var(--gray7); } } /* Animations */ @keyframes finger-inner { from, 80%, to { transform: translate(0, 0); } 40% { animation-timing-function: cubic-bezier(0.32, 0, 0.67, 0); transform: translate(0, -3px); } } @keyframes thumb-inner { from, 80%, to { transform: translate(0, 0) skewY(0); } 40% { animation-timing-function: cubic-bezier(0.32, 0, 0.67, 0); transform: translate(-0.5px, -3px) skewY(-15deg); } } @keyframes pinky { from, 80%, to { transform: translate(0, 3.5px); } 40% { animation-timing-function: cubic-bezier(0.32, 0, 0.67, 0); transform: translate(0, 1.2px); } } @keyframes ring { from, 80%, to { transform: translate(6.5px, 1.8px); } 40% { animation-timing-function: cubic-bezier(0.32, 0, 0.67, 0); transform: translate(6.5px, 0.5px); } } @keyframes index { from, 80%, to { transform: translate(19.5px, 2.5px); } 40% { animation-timing-function: cubic-bezier(0.32, 0, 0.67, 0); transform: translate(19.5px, 1.2px); } } </style> </head> <body translate="no"> <svg class="hand" viewBox="0 0 32 20" width="32px" height="20px"> <clipPath id="finger-pinky"> <rect rx="2.5" ry="2.5" width="6" height="15" /> </clipPath> <clipPath id="finger-ring"> <rect rx="2.5" ry=&qu.........完整代码请登录后点击上方下载按钮下载查看
网友评论0