Web Component实现炫酷鼠标悬停图标按钮动画效果代码
代码语言:html
所属分类:悬停
代码描述:Web Component实现炫酷鼠标悬停图标按钮动画效果代码
代码标签: Web Component 炫酷 鼠标 悬停 图标 按钮 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/reset.min.css"> <style> :root { --space: 1rem; --bg: #09090b; --fg: #e3e3e3; --surface-1: #101012; --surface-2: #27272a; --surface-3: #52525b; --ease-out: cubic-bezier(0.5, 1, 0.89, 1); --ease-in-out: cubic-bezier(0.45, 0, 0.55, 1); } * { box-sizing: border-box; } height, body { height: 100%; } body { display: grid; color: var(--fg); background: var(--bg); padding: var(--space); min-height: 100vh; } main { display: grid; grid-template-columns: repeat(var(--count, 1), 1fr); gap: var(--space); margin: auto; inline-size: min(var(--max, 15rem), 100%); @media (min-width: 25rem) { --count: 2; --max: 30rem; } @media (min-width: 45rem) { --count: 4; --max: 60rem; } } .card { position: relative; overflow: hidden; display: grid; grid-template-areas: "card"; place-items: center; aspect-ratio: 4/5; border: 1px solid var(--surface-2); isolation: isolate; transition: border-color 200ms var(--ease-out); -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; &::before { content: ""; position: absolute; inset: 0; background: radial-gradient( circle at bottom left, transparent 55%, var(--surface-1) ); pointer-events: none; box-shadow: var(--bg) -0.5cqi 0.5cqi 2.5cqi inset; transition: opacity 900ms var(--ease-out); } &::after { content: ""; position: absolute; inset: 0; margin: auto; aspect-ratio: 1; background: radial-gradient(circle, var(--bg), transparent 65%); opacity: 0; transition: opacity 800ms var(--ease-out); } > * { grid-area: card; } svg { position: relative; z-index: 1; width: 30%; height: auto; color: var(--surface-3); transition: 300ms var(--ease-out); transition-property: color, scale; } &:hover { border-color: var(--active-color, var(--fg)); transition: border-color 800ms var(--ease-in-out); } &:hover svg { color: var(--active-color, var(--fg)); scale: 1.1; transition: 300ms var(--ease-in-out); } &:hover::before { opacity: 0; } &:hover::after { opacity: 1; } } </style> </head> <body translate="no"> <main> <div class="card"> <pixel-canvas></pixel-canvas> <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentcolor" viewBox="0 0 256 256"> <path d="M216,42H40A14,14,0,0,0,26,56V200a14,14,0,0,0,14,14H216a14,14,0,0,0,14-14V56A14,14,0,0,0,216,42ZM40,54H216a2,2,0,0,1,2,2V98H38V56A2,2,0,0,1,40,54ZM38,200V110H98v92H40A2,2,0,0,1,38,200Zm178,2H110V110H218v90A2,2,0,0,1,216,202Z"></path> </svg> </div> <div class="card" style="--active-color: #e0f2fe"> <pixel-canvas data-gap="10" data-speed="25" data-colors="#e0f2fe, #7dd3fc, #0ea5e9"></pixel-canvas> <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentcolor" viewBox="0 0 256 256"> <path d="M67.84,92.61,25.37,128l42.47,35.39a6,6,0,1,1-7.68,9.22l-48-40a6,6,0,0,1,0-9.22l48-40a6,6,0,0,1,7.68,9.22Zm176,30.78-48-40a6,6,0,1,0-7.68,9.22L230.63,128l-42.47,35.39a6,6,0,1,0,7.68,9.22l48-40a6,6,0,0,0,0-9.22Zm-81.79-89A6,6,0,0,0,154.36,38l-64,176A6,6,0,0,0,94,221.64a6.15,6.15,0,0,0,2,.36,6,6,0,0,0,5.64-3.95l64-176A6,6,0,0,0,162.05,34.36Z"></path> </svg> </div> <div c.........完整代码请登录后点击上方下载按钮下载查看
网友评论0