css+svg实现带进度条显示的上传按钮效果代码
代码语言:html
所属分类:表单美化
代码描述:css+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"> <link rel='stylesheet' href='https://fonts.googleapis.com/css2?family=Hind&display=swap'> <style> * { border: 0; box-sizing: border-box; margin: 0; padding: 0; } :root { --bg: #e3e4e8; --fg: #17181c; --stroke: #86a6f9; --success: #25f42f; font-size: calc(20px + (40 - 20) * (100vw - 320px) / (1280 - 320)); } body, button { font: 1em/1.5 Hind, sans-serif; } body { background: var(--bg); color: var(--fg); display: grid; place-items: center; height: 100vh; } .upload-btn { --dur: 0.25s; background: #255ff4; border-radius: 1.25em; color: #fff; cursor: pointer; padding: 0.5em 1em; position: relative; text-align: center; transition: all 0.1s linear; width: 6em; -webkit-tap-highlight-color: #0000; -webkit-appearance: none; appearance: none; } .upload-btn:disabled { cursor: not-allowed; } .upload-btn:not(:disabled):focus, .upload-btn:not(:disabled):hover { background: #0b46da; } .upload-btn:focus { outline: transparent; } .upload-btn-border { display: block; overflow: visible; pointer-events: none; position: absolute; top: 0; left: 0; width: 100%; height: auto; } .upload-btn-border rect { stroke: var(--stroke); } .upload-btn-text { display: inline-block; } .upload-btn-running { text-align: right; } .upload-btn-running .upload-btn-text { animation: flyIn2 var(--dur) ease-in forwards; } .upload-btn-done .upload-btn-border { animation: sinkInA var(--dur) ease-in forwards; } .upload-btn-done .upload-btn-border rect { animation: sinkInB var(--dur) ease-in forwards; } .upload-btn-done .upload-btn-text { animation: pulseIn var(--dur) linear forwards; color: var(--success); } .upload-btn-ready .upload-btn-text { animation: flyIn1 var(--dur) ease-in forwards; } /* Dark theme */ @media (prefers-color-scheme: dark) { :root { --bg: #17181c; --fg: #e3e4e8; } } /* Animations */ @keyframes flyIn1 { from { opacity: 0; transform: translateY(33%); } to { opacity: 1; transform: translateY(0); } } @keyframes flyIn2 { from { opacity: 0; /* (buttonWidth / 2 - rightPadding) + (lastDigit + "%") */ transform: translate(calc(-2em + 2ch),33%); } to { opacity: 1; transform: translate(calc(-2em + 2ch),0); } } @keyframes pulseIn { from { transform: scale(0); } 33% { transform: scale(2.17,2.17); } 67% { transform: scale(1.17,1.17); } to { transform: scale(1.5); } } @keyframes sinkInA { from { transform: scale(1,1); } 25%, to { /* 120/124, 50/54 */ transform: scale(0.968,0.925); } } @keyframes sinkInB { from { stroke-width: 4; } 25%, to { stroke-width: 0; } } </style> </head> <body> <button id="upload" class="upload-btn" type="button"> <svg class="upload-.........完整代码请登录后点击上方下载按钮下载查看
网友评论0