js实现彩色圆环进度条时钟效果代码

代码语言:html

所属分类:进度条

代码描述:js实现彩色圆环进度条时钟效果代码

代码标签: 圆环 进度条 时钟

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">





    <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%);
        	font-size: calc(16px + (24 - 16) * (100vw - 320px) / (1280 - 320));
        }
        body, button {
        	color: var(--fg);
        	font: 1em/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
        }
        body {
        	background-color: var(--bg);
        	height: 100vh;
        	display: grid;
        	place-items: center;
        }
        
        .progress-clock {
        	display: grid;
        	justify-content: center;
        	align-content: center;
        	position: relative;
        	text-align: center;
        	width: 16em;
        	height: 16em;
        }
        .progress-clock__time-date,
        .progress-clock__time-digit,
        .progress-clock__time-colon,
        .progress-clock__time-ampm {
        	transition: color 0.2s linear;
        	-webkit-user-select: none;
        	-moz-user-select: none;
        	user-select: none;
        }
        .progress-clock__time-date,
        .progress-clock__time-digit {
        	background: transparent;
        }
        .progress-clock__time-date,
        .progress-clock__time-ampm {
        	grid-column: 1 / 6;
        }
        .progress-clock__time-date {
        	font-size: 0.75em;
        	line-height: 1.33;
        }
        .progress-clock__time-digit,
        .progress-clock__time-colon {
        	font-size: 2em;
        	font-weight: 400;
        	grid-row: 2;
        }
        .progress-clock__time-colon {
        	line-height: 1.275;
        }
        .progress-clock__time-ampm {
        	cursor: default;
        	grid-row: 3;
        }
        .progress-clock__rings {
        	display: block;
        	position: absolute;
        	top: 0;
        	left: 0;
        	width: 100%;
        	height: 100%;
        	z-index: -1;
        }
        .progress-clock__ring {
        	opacity: 0.1;
        }
        .progress-clock__ring-fill {
        	transition:
        		opacity 0s 0.3s linear,
        		stroke-dashoffset 0.3s ease-in-out;
        }
        .progress-clock__ring-fill--360 {
        	opacity: 0;
        	stroke-dashoffset: 0;
        	transition-duration: 0.3s;
        }
        [data-group]:focus {
        	outline: transparent;
        }
        [data-units] {
        	transition: opacity 0.2s linear;
        }
        [data-group="d"]:focus,
        [data-group="d"]:hover {
        	color: hsl(333,90%,55%);
        }
        [data-group="h"]:focus,
        [data-group="h"]:hover {
        	color: hsl(33,90%,55%);
        }
        [data-group="m"]:focus,
        [data-group="m"]:hover {
        	color: hsl(213,90%,55%);
        }
        [data-group="s"]:focus,
        [data-group="s"]:hover {
        	color: hsl(273,90%,55%);
        }
        [data-group]:focus ~ .progress-clock__rings [data-units],
        [data-group]:hover ~ .progress-clock__rings [data-units] {
        	opacity: 0.2;
        }
        [data-group="d"]:focus ~ .progress-clock__rings [data-units="d"],
        [data-group="d"]:hover ~ .progress-clock__rings [data-units="d"],
        [data-group="h"]:focus ~ .progress-clock__rings [data-units="h"],
        [data-group="h"]:hover ~ .progress-clock__rings [data-units="h"],
        [data-group="m"]:focus ~ .progress-clock__rings [data-units="m"],
        [data-group="m"]:hover ~ .progress-clock__rings [data-units="m"],
        [data-group="s"]:focus ~ .progress-clock__rings [data-units="s"],
        [data-group="s"]:hover ~ .progress-clock__rings [data-units="s"] {
        	opacity: 1;
        }
        
        /* Dark theme */
        @media (prefers-color-scheme: dark) {
        	:root {
        		--bg: hsl(var(--hue),10%,10%);
        		--fg: hsl(var(--hue),10%,90%);
        	}
        	.progress-clock__ring {
        		opacity: 0.2;
        	}
        }
    </style>



</head>

<body>
    <div id="clock" class="progress-clock">
        <button class="progress-clock__time-date" data-group="d" type="button">
		<small data-unit="w">Sunday</small><br>
		<span data-unit="mo">January</span>
		<span data-unit="d">1</span>
	</button>
        <button class="progress-clock__time-digit" data-unit="h" data-group="h" type="button">12</button><span class="progress-clock__time-colon">:</span><button class="progress-clock__time-digit" data-unit="m" data-group="m" type="button">00</button>
        <span
            class="progress-clock__time-colon">:</span><button class="progress-clock__time-digit" data-unit="s" data-group="s" type="button">00</button>
            <span class="progress-clock__time-ampm" data-unit="ap">AM</span>
            <svg class="progress-clock__rings" width="256" height="256" viewBox="0 0 256 256">
		<defs>
			<linearGradient id="pc-red" x1="1" y1="0.5" x2="0" y2="0.5">
				<stop offset="0%" stop-color="hsl(343,90%,55%)" />
				<stop offset="100%" stop-color="hsl(323,90%,55%)" />
			</linearGradient>
			<linearGradient id="pc-yellow" x1="1" y1="0.5" x2="0" y2="0.5">
				<stop offset="0%" stop-color="hsl(43,90%,55%)" />
				<stop offset="100%" stop-color="hsl(23,90%,55%)" />
			</linearGradient>
			<linearGradient id="pc-blue" x1="1" y1="0.5" x2="0" y2="0.5">
				<stop offset="0%" stop-color="hsl(223,90%,55%)" />
				<stop offset="100%" stop-color="hsl(203,90%,55%)" />
			</linearGradient>
			<linearGradient id="pc-purple" x1="1" y1="0.5" x2="0" y2="0.5">
				<stop offset="0%" stop-color="hsl(283,90%,55%)" />
				<stop offset="100%" stop-color="hsl(263,90%,55%)" />
			</linearGradient>
		</defs>
		<!-- Days of Month -->
		<g data-units="d">
			<circle class="progress-clock__ring" cx="128" cy="128" r="74" fill="none" opacity="0.1" stroke="url(#pc-red)" stroke-width="12" />
			<circle class="progress-clock__ring-fill" data-ring="mo" cx="128" cy="128" r="74" fill="none" stroke="url(#pc-red)" stroke-width="12" stroke-dasharray="465 465" stroke-dashoffset="465" stroke-linecap="round" transform="rotate(-90,128,128)" />
		</g>
		<!-- Hours of Day -->
		<g data-units="h">
			<circle class="progress-clo.........完整代码请登录后点击上方下载按钮下载查看

网友评论0