js实现一个分段下载进度条动画效果代码
代码语言:html
所属分类:进度条
代码描述:js实现一个分段下载进度条动画效果代码
下面为部分代码预览,完整代码请点击下载或在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 { --hue: 223; --bg: hsl(var(--hue),10%,90%); --fg: hsl(var(--hue),10%,10%); --primary: hsl(var(--hue),90%,55%); --disabled: hsl(var(--hue),10%,75%); font-size: calc(16px + (24 - 16) * (100vw - 320px) / (1280 - 320)); } body, button { font: 1em/1.5 Hind, sans-serif; } body { background: var(--bg); color: var(--fg); height: 100vh; display: grid; place-items: center; } button { background: hsl(var(--hue),90%,55%); border-radius: 0.2em; color: #fff; cursor: pointer; margin: auto; padding: 0.5em 1em; position: relative; left: 50%; transform: translateX(-50%); text-align: center; transition: background 0.15s linear; } button:hover { background: hsl(var(--hue),90%,45%); } .sp { --incTrans: 0.1; /* in seconds */ display: block; margin-bottom: 1.5em; overflow: visible; width: 12.75em; height: 1.5em; } .sp__bar, .sp__hub { stroke: var(--disabled); } .sp__hub--done, .sp__dot--done { transition: r 0.2s cubic-bezier(0,0,0.33,1.67); } .sp__hub--done { r: 10px; } .sp__hub--done ~ .sp__bar-fill { transition: all calc(1s * var(--incTrans)) linear; } .sp__bar-fill, .sp__hub-fill { stroke: var(--primary); } .sp__bar-fill { stroke-dasharray: 40 40; stroke-dashoffset: 40; } .sp__hub-fill { stroke-dasharray: 0 62.8 0; visibility: hidden; } .sp__hub-fill--done { stroke-dasharray: 31.4 0 31.4; transition: all 0.2s 0.2s ease-out; visibility: visible; } .sp__dot { fill: var(--primary); } .sp__dot--done { r: 4px; transition-delay: 0.4s; } .status { margin-bottom: 4.5em; text-align: center; } @media (prefers-color-scheme: dark) { :root { --bg: hsl(var(--hue),10%,10%); --fg: hsl(var(--hue),10%,90%); --primary: hsl(var(--hue),90%,65%); --disabled: hsl(var(--hue),10%,30%); } } </style> </head> <body > <main> <svg class="sp" width="204px" height="24px" viewBox="0 0 204 24" xmlns="http://www.w3.org/2000/svg"> <!-- Part 1 --> <circle data-dot="1" class="sp__dot" cx="12" cy="12" r="0" fill="#000"/> <line class="sp__bar" x1="22" y1="12" x2="62" y2="12" fill="none" stroke="#000" stroke-width="4" /> <circle data-hub="1" class="sp__hub" cx="12" cy="12" r="2" fill="none" stroke="#000" stroke-width="4" /> <line data-bar="1" class="sp__bar-fill" x1="22" y1="12" x2="62" y2="12" fill="none" stroke="#000" stroke-width="4" /> <circle data-hub-fill="1" class="sp__hub-fill" cx="12" cy="12" r="10" fill="none" stroke-width="4" transform="rotate(180,12,12)" /> <!-- Part 2 --> <circle data-dot="2" class="sp__dot" cx="72" cy="12" r="0" fill="#000"/> <line class="sp__bar" x1="82" y1="12" x2="122" y2="12" fill="none" stroke="#000" stroke-width="4" /> <circle data-hub="2" class="sp__hub" cx="72" cy="12" r="2" fill="none" stroke="#000" stroke-width="4" /> <line data-bar="2" class="sp__bar-fill" x1="82" y1="12" x2="122" y2="12" fill="none" stroke="#000" stroke-width="4" /> <circle data-hub-fill="2" class="sp__hub-fill" cx="72" cy="12" r="10" fill="none" stroke-width="4" transform="rotate(180,72,12)" /> <!-- Part 3 --> <circle data-dot="3" class="sp__dot" cx="132" cy="12" r="0" fill="#000"/> <line class="sp__bar" x1="142" y1="12" x2=".........完整代码请登录后点击上方下载按钮下载查看
网友评论0