纯css实现svg动画过渡效果
代码语言:html
所属分类:动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Varela+Round&display=swap'> <style> .nav { --color: #ffffff; background: none; width: 100px; height: 56px; position: relative; display: -webkit-box; display: flex; -webkit-box-pack: center; justify-content: center; -webkit-box-align: center; align-items: center; } .nav svg { fill: none; stroke: var(--color); stroke-width: 7px; stroke-linecap: round; stroke-linejoin: round; } .nav svg use:nth-of-type(1) { opacity: 1; stroke-dashoffset: 221; stroke-dasharray: 46 249; -webkit-transition: stroke-dashoffset.12s linear .2s, stroke-dasharray .12s linear .2s, opacity 0s linear .2s; transition: stroke-dashoffset.12s linear .2s, stroke-dasharray .12s linear .2s, opacity 0s linear .2s; } .nav svg use:nth-of-type(2) { -webkit-animation: stroke-animation-reverse 1.2s ease-out forwards; animation: stroke-animation-reverse 1.2s ease-out forwards; } .nav input { position: absolute; height: 100%; width: 100%; z-index: 2; cursor: pointer; opacity: 0; } .nav input:checked + svg use:nth-of-type(1) { stroke-dashoffset: 175; stroke-dasharray: 0 295; opacity: 0; -webkit-transition: stroke-dashoffset.07s linear .07s, stroke-dasharray .07s linear .07s, opacity 0s linear .14s; transition: stroke-dashoffset.07s linear .07s, stroke-dasharray .07s linear .07s, opacity 0s linear .14s; } .nav input:checked + svg use:nth-of-type(2) { -webkit-animation: stroke-animation 1.2s ease-out forwards; animation: stroke-animation 1.2s ease-out forwards; } @-webkit-keyframes stroke-animation { 0% { stroke-dashoffset: 295; stroke-dasharray: 25 270; } 50% { stroke-dashoffset: 68; stroke-dasharray: 59 236; } 65% { stroke-dashoffset: 59; stroke-dasharray: 59 236; } 100% { stroke-dashoffset: 68; stroke-dasharray: 59 236; } } @keyframes stroke-animation { .........完整代码请登录后点击上方下载按钮下载查看
网友评论0