svg+js实现按钮点击变形动画效果代码
代码语言:html
所属分类:动画
代码描述:svg+js实现按钮点击变形动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> html, body { height: 100%; } body { align-items: center; background-color: #425ad1; background-image: linear-gradient(43deg, #425ad1 0%, #c851c0 46%, #ffcd70 100%); color: white; display: flex; font-family: "rift", sans-serif; font-size: 24px; font-weight: 600; justify-content: center; } button { appearance: none; -moz-appearance: none; -webkit-appearance: none; background-color: #fff; border: none; border-radius: 50px; cursor: pointer; height: 50px; outline: none; position: relative; width: 50px; } button.active #open-cubes rect, button.active #close-cubes rect { fill: #c851c0; } button svg { position: absolute; left: 0; top: 0; } button svg #open-cubes rect, button svg #close-cubes rect { fill: #294bf5; transition: fill 600ms ease; } button svg #close-cubes rect { opacity: 0; } .spin-in { -webkit-animation: spin-in 1300ms ease 1 forwards 10ms; animation: spin-in 1300ms ease 1 forwards 10ms; transform-origin: center; } .spin-out { -webkit-animation: spin-out 1300ms ease 1 forwards 10ms; animation: spin-out 1300ms ease 1 forwards 10ms; transform-origin: center; } @-webkit-keyframes spin-in { 0% { opacity: 0; transform: rotate(0deg); } 100% { opacity: 1; transform: rotate(720deg); } } @keyframes spin-in { 0% { opacity: 0; transform: rotate(0deg); } 100% { opacity: 1; transform: rotate(720deg); } } @-webkit-keyframes spin-out { 0% { opacity: 1; transform: rotate(720deg); } 100% { opacity: 0; transform: rotate(0deg); } } @keyframes spin-out { 0% { opacity: 1; transform: rotate(720deg); } 100% { opacity: 0; transform: rotate(0deg); } } </style> </head> <bod> <button id="menu-toggle"> <svg height="50" width="50" viewBox="0 0 50 50" xmlns="http://www.w3.org/2000/svg"> <g id="open-cubes"> <g id="top-cubes"> <rect x="12" y="19" width="2" height="2" /> <rect x="12" y="21" width="2" height="2" /> <rect x="14" y="19" width="2" height="2" /> <rect x="14" y="21" width="2" height="2" /> <rect x="16" y="19" width="2" height="2" /> <rect x="16" y="21" width="2" height="2" /> <rect x="18" y="19" width="2" height="2" /> <rect x="18" y="21" width="2" height="2" /> <rect x="20" y="19" width="2" height="2" /> <rect x="20" y="21" width="2" height="2" /> <rect x="22" y="19" width="2" height="2" /> <rect x="22" y="21" width="2" height="2" /> <rect x="24" y="19" width="2" height="2" /> <rect x="24" y="21" width="2" height="2" /> <rect x="26" y="19" width="2" height="2" /> <rect x="26" y="21" width="2" height="2" /> <rect x="28" y="19" width="2" height="2" /> <rect x="28" y="21" width="2" height="2" /> <rect x="30" y="19" width="2" height="2" /> <rect x="30" y="21" width="2" height="2" /> <rect x="32" y="19" width="2" height="2" /> <rect x="32" y="21" width="2" height="2" /> <rect x="34" y="19" width="2" height="2" /> <rect x="34" y="21" width="2" height="2" /> <rect x="36" y="19" width="2" height="2" /> <rect x="36" y="21" width="2" height="2" /> </g> <g id="bottom-cubes"> <rect x="12" y="27" width="2" height="2" /> <rect x="12" y="29" width="2" height="2" /> <rect x="14" y="27" width="2" height="2" /> <rect x="14" y="29" width="2" height="2" /> <rect x="16" y="27" width="2" height="2" /> <rect x="16" y="29" width="2" height="2" /> <rect x="18" y="27" width="2" height="2" /> <rect x="18" y="29" width="2" height="2" /> <rect x="20" y="27" width="2" height="2" /> <rect x="20" y="29" width="2" height="2" /> <rect x="22" y="27" width="2" height="2" /> <rect x="22" y="29" width="2" height="2" /> <rect x="24" y="27" width="2" height="2" /> <rect x="24" y="29" width="2" height="2" /> <rect x="26" y="27" width="2" height="2" /> <rect x="26" y="29" width="2" height="2" /> <rect x="28" y="27" width="2" height="2" /> <rect x="28" y="29" width="2" height="2" /> <rect .........完整代码请登录后点击上方下载按钮下载查看
网友评论0