js实现创意时钟时间显示效果代码
代码语言:html
所属分类:其他
代码描述:js实现创意时钟时间显示效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
html, body {
margin: 0;
padding: 0;
overflow: hidden;
}
canvas {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<canvas id="render"></canvas>
<script>
const canvas = document.getElementById("render");
const context = canvas.getContext('2d');
const toggleTime = 300; // 300ms
class Easing {
static easeInOutQuad(x) {
return x < 0.5 ? 2 * x * x : 1 - Math.pow(-2 * x + 2, 2) / 2;
}
static easeOutBounce(x) {
const n1 = 7.5625;
const d1 = 2.75;
if (x < 1 / d1) {
return n1 * x * x;
} else if (x < 2 / d1) {
return n1 * (x -= 1.5 / d1) * x + 0.75;
} else if (x < 2.5 / d1) {
return n1 * (x -= 2.25 / d1) * x + 0.9375;
} else {
return n1 * (x -= 2.625 / d1) * x + 0.984375;
}
}
static easeInOutBounce(x) {
return x < 0.5 ?
(1 - Easing.easeOutBounce(1 - 2 * x)) / 2 :
(1 + Easing.easeOutBounce(2 * x - 1)) / 2;
}
static easeInOutCirc(x) {
return x < 0.5 ?
(1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2 :
(Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2;
}}
class RGB {
static clamp(value, min, max) {
if (value < min)
return min;
if (value > max)
return max;
return value;
}
constructor(r, g, b) {
this.r = RGB.clamp(r, 0, 255);
this.g = RGB.clamp(g, 0, 255);
this.b = RGB.clamp(b, 0, 255);
}
toString() {
return `rgb(${this.r}, ${this.g}, ${this.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0