anime+svg实现一个可以调时间的时钟表效果代码

代码语言:html

所属分类:其他

代码描述:anime+svg实现一个可以调时间的时钟表效果代码圆套小圆旋转动画效果代码

代码标签: 可以 调时 间的 钟表 效果

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


<!DOCTYPE html>
<html lang="en" >

<head>

  <meta charset="UTF-8">

  
  
  
  
<style>
@import url("https://fonts.googleapis.com/css?family=Barlow|Barlow+Condensed&display=swap");

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}
/* position the svg and div wrapping the controls one atop the other */
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #262728;
  font-family: "Barlow", sans-serif;
}
/* have the clock describing the svg expand to cover a sizeable portion of the viewport */
svg {
  margin-top: 1rem;
  width: 60vmin;
  height: auto;
  filter: url(#shadow-large);
}
svg text {
  font-family: "Barlow Condensed", sans-serif;
}

/* display the controls side by side */
.controls {
  display: flex;
  flex-wrap: wrap;
  margin-top: 2rem;
}
/* display the button+span elements in columns */
.controls div {
  text-align: center;
  display: flex;
  flex-direction: column;
  margin: 1rem;
}
/* style the buttons with the same colors used for the clock */
.controls div button {
  border: none;
  border-radius: 50%;
  background: #ea3f3f;
  padding: 0.25rem;
  color: #fff;
  width: 48px;
  height: 48px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.5rem;
  filter: url(#shadow-large);
  margin: 0.5rem 0;
}
.controls div span {
  color: #fff;
}
</style>


</head>

<body >
  <!-- svg making up the clock -->
<svg viewBox="0 0 100 100" width="100" height="100">
    <defs>
        <!-- filters describing the shadows, applied on the larger and smaller shapes -->
        <filter id="shadow-large">
            <feDropShadow dx="0" dy="0" stdDeviation="4"/>
        </filter>
        <filter id="shadow-small">
                <feDropShadow dx="0" dy="0" stdDeviation="0.2"/>
        </filter>

        <!-- mask used to cut out a sliver of the overlaid circle -->
        <mask
            id="mask">
            <g transform="translate(50 50)">
                <!-- starting at -15, incrementing by 30 for each hour -->
                <g
                    class="hours" transform="rotate(-15)">
                    <circle
                        cx="0"
                        cy="0"
                        r="50"
                        fill="#fff">
                    </circle>
                    <path
                        d="M 0 -50 v 50 l 28.86 -50"
                        fill="#000">
                    </path>
                </g>
            </g>
        </mask>
    </defs>

    <!-- circle making up the bottom of the clock -->
    <circle
        cx="50"
        cy="50"
        r="46"
        fill="#303335">
    </circle>

    <!-- circle with the accent color, overlaid before the text elements -->
    <circle
        cx="50"
        cy="50"
        r="42"
        fill="#EA3F3F"
        filter="url(#shadow-large)">
    </circle>

    <!-- text elements, positioned from the center around the clock -->
    <g
        class="clock--face"
        font-size="8px"
        transform="translate(50 50)"
        text-anchor="middle"
        dominant-baseline="middle">
        <!-- the elements are included through the script, at intervals of 30 degrees -->
        <!--
        <text
            transform="rotate(-90) translate(35 0) rotate(90)" >
            12
        </text>

        <text
            transform="rotate(-0) translate(35 0) rotate(0)" >
            03
        </text>
        -->
    </g>

    <!-- circle overlaid on the accent circle and text elements -->
    <circle
        mask="url(#mask)"
        cx="50"
        cy="50"
        r="50"
        fill="#303335">
    </circle>

    <!-- smaller circle on which the hands sit -->
    <circle
        cx="50"
        cy="50"
        r="4"
        filter="url(#shadow-small)"
        fill="#303335">
    </circle>

    <!-- clock's hands -->
    <!-- centered in the clock and rotated according to the passage of time in the 0-360 range -->
    <g
        class="hands"
        transform="translate(50 50)"
        >
        <g
            class="minutes"
            transform="rotate(240)"> <!-- change rotation of this group to affect both clock's hand -->
            <path
                fill="#fff"
                d="M -0.4 8 h 0.8 v -33 h -0.8 z">
            </path>
            <circle
                fill="#303335"
                cx="0"
                cy="0"
                r="0.6">
            </circle>
        </g>

        <g
            class="seconds"
            transform="rotate(80)"> <!-- change rotation of this group to affect both clock's hand -->
            <path
                fill="#EA3F3F"
                d="M -0.4 10 h 0.8 v -45 h -0.8 z">
            </path>
            <circle
                stroke-width="0.4"
                stroke="#EA3F3F"
                fill="#303335"
                cx="0"
                cy="0"
                r="0.8">
            </cir.........完整代码请登录后点击上方下载按钮下载查看

网友评论0