js+css实现文字布料重力交互感应触摸动画代码
代码语言:html
所属分类:动画
代码描述:js+css实现文字布料重力交互感应触摸动画代码
代码标签: js css 文字 布料 重力 交互 感应 触摸 动画 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
@import url("https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300..900;1,300..900&display=swap");
body {
background: #EEE;
margin: 0;
display: flex;
min-height: 100vh;
align-items: center;
justify-content: center;
overflow: hidden;
}
canvas {
max-height: 100vh;
max-width: 100vw;
height: auto;
width: auto;
/* border: 1px solid silver; */
}
#container {
box-shadow: 0 0 20px rgba(0,0,0,.05);
border: 1px solid rgba(0,0,0,.1);
position: relative;
display: flex;
align-items: center;
justify-content: center;
touch-action: none;
}
h1 {
font-family: Rubik;
font-size: 100px;
font-weight: 800;
line-height: 1em;
position: absolute;
color: #fff;
}
</style>
</head>
<body translate="no">
<div id="container"></div>
<script type="module">
// ========== 基础工具函数 ==========
const lerp = (a, b, t) => a + (b - a) * t;
const lerpPoint = (p1, p2, t) => ({
x: lerp(p1.x, p2.x, t),
y: lerp(p1.y, p2.y, t),
});
function smoothstep(edge0, edge1, x) {
let t = Math.max(0, Math.min(1, (x - edge0) / (edge1 - edge0)));
return t * t * (3 - 2 * t);
}
const randomBetween = (a, b) => a + Math.random() * (b - a);
// 注意:randomOS 每次加载都会生成新种子,如需固定结果可改为常量
const randomOS = Math.random() * 200;
const hash = (x, os = randomOS) =>
Math.abs(Math.sin((x + os) * 9174986346) * 1964286753) % 1;
// ========== 网格坐标工具 ==========
function getPoint(id, w) {
return {
x: id % w,
y: Math.floor(id / w),
};
}
functio.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0