style: 重构 index.html 视觉(霓虹极光背景、玻璃拟态卡片、渐变发光数字、滑动光柱)
This commit is contained in:
+342
-133
@@ -3,82 +3,222 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>BMI 与每日热量计算器</title>
|
<title>BMI 与每日热量计算器 · Neon</title>
|
||||||
<style>
|
<style>
|
||||||
:root{
|
:root{
|
||||||
--bg:#f6f7f9; --card:#fff; --line:#e3e6ea; --text:#1f2933; --muted:#6b7280;
|
--bg0:#04050c; --bg1:#0a1020;
|
||||||
--emerald:#059669; --amber:#b45309; --sky:#0284c7; --rose:#be123c;
|
--text:#e8eefc; --muted:#8b9ac0;
|
||||||
|
--c1:#22d3ee; --c2:#a855f7; --c3:#f472b6; --c4:#34d399; --c5:#fbbf24;
|
||||||
|
--glass:rgba(255,255,255,.055);
|
||||||
|
--stroke:rgba(255,255,255,.12);
|
||||||
|
--neon:linear-gradient(100deg,#22d3ee,#a855f7,#f472b6,#34d399,#22d3ee);
|
||||||
|
}
|
||||||
|
*{box-sizing:border-box}
|
||||||
|
body{
|
||||||
|
margin:0; padding:34px 16px 64px; color:var(--text); line-height:1.65; overflow-x:hidden;
|
||||||
|
background:
|
||||||
|
radial-gradient(1200px 700px at 12% -12%, #10203f 0%, transparent 60%),
|
||||||
|
radial-gradient(900px 620px at 106% 8%, #2a1040 0%, transparent 55%),
|
||||||
|
radial-gradient(820px 700px at 50% 122%, #062b2c 0%, transparent 60%),
|
||||||
|
linear-gradient(180deg,var(--bg1),var(--bg0) 72%);
|
||||||
|
background-attachment:fixed;
|
||||||
|
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;
|
||||||
|
}
|
||||||
|
/* ===== 背景:极光光斑 + 网格 ===== */
|
||||||
|
.aurora{position:fixed;inset:-22vh -12vw;z-index:-2;filter:blur(72px);opacity:.55;pointer-events:none}
|
||||||
|
.aurora i{position:absolute;display:block;border-radius:50%;mix-blend-mode:screen;animation:drift 24s ease-in-out infinite}
|
||||||
|
.aurora i:nth-child(1){width:46vw;height:46vw;left:2%;top:4%;background:radial-gradient(circle,#0891b2,transparent 66%)}
|
||||||
|
.aurora i:nth-child(2){width:38vw;height:38vw;right:3%;top:-2%;background:radial-gradient(circle,#7c3aed,transparent 66%);animation-duration:28s;animation-delay:-7s}
|
||||||
|
.aurora i:nth-child(3){width:44vw;height:44vw;left:26%;bottom:-10%;background:radial-gradient(circle,#db2777,transparent 66%);animation-duration:32s;animation-delay:-13s}
|
||||||
|
.aurora i:nth-child(4){width:30vw;height:30vw;right:16%;bottom:4%;background:radial-gradient(circle,#059669,transparent 66%);animation-duration:26s;animation-delay:-4s}
|
||||||
|
@keyframes drift{
|
||||||
|
0%,100%{transform:translate3d(0,0,0) scale(1)}
|
||||||
|
33%{transform:translate3d(6vw,-5vh,0) scale(1.12)}
|
||||||
|
66%{transform:translate3d(-5vw,4vh,0) scale(.93)}
|
||||||
|
}
|
||||||
|
.mesh{position:fixed;inset:0;z-index:-1;pointer-events:none;opacity:.5;
|
||||||
|
background-image:linear-gradient(rgba(148,163,184,.075) 1px,transparent 1px),
|
||||||
|
linear-gradient(90deg,rgba(148,163,184,.075) 1px,transparent 1px);
|
||||||
|
background-size:58px 58px;
|
||||||
|
-webkit-mask-image:radial-gradient(ellipse 78% 58% at 50% 0%,#000 38%,transparent 100%);
|
||||||
|
mask-image:radial-gradient(ellipse 78% 58% at 50% 0%,#000 38%,transparent 100%);
|
||||||
|
}
|
||||||
|
main{max-width:840px;margin:0 auto;position:relative}
|
||||||
|
|
||||||
|
/* ===== 标题 ===== */
|
||||||
|
h1{font-size:clamp(25px,4.8vw,36px);margin:0 0 10px;letter-spacing:.4px;line-height:1.22;font-weight:800}
|
||||||
|
h1 .neon{background:var(--neon);background-size:280% 100%;-webkit-background-clip:text;background-clip:text;
|
||||||
|
color:transparent;animation:flow 8s linear infinite}
|
||||||
|
@keyframes flow{to{background-position:280% 0}}
|
||||||
|
.sub{color:var(--muted);font-size:13.5px;margin:0 0 16px;max-width:62ch}
|
||||||
|
.badges{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:22px}
|
||||||
|
.badge{font-size:11.5px;letter-spacing:.3px;padding:5px 11px;border-radius:999px;color:#cfe0ff;
|
||||||
|
border:1px solid var(--stroke);background:rgba(255,255,255,.04);backdrop-filter:blur(6px)}
|
||||||
|
.badge b{color:#fff}
|
||||||
|
|
||||||
|
/* ===== 玻璃卡片 ===== */
|
||||||
|
.panel{position:relative;background:var(--glass);border:1px solid var(--stroke);border-radius:20px;
|
||||||
|
padding:18px;margin-bottom:16px;backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);
|
||||||
|
box-shadow:0 20px 55px -32px rgba(0,0,0,.95), inset 0 1px 0 rgba(255,255,255,.06);
|
||||||
|
animation:rise .62s cubic-bezier(.2,.85,.3,1) both}
|
||||||
|
.panel::before{content:"";position:absolute;inset:0;border-radius:20px;padding:1px;pointer-events:none;opacity:.85;
|
||||||
|
background:linear-gradient(140deg,rgba(34,211,238,.5),rgba(168,85,247,.38) 42%,rgba(255,255,255,0) 72%);
|
||||||
|
-webkit-mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);
|
||||||
|
mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);
|
||||||
|
-webkit-mask-composite:xor;mask-composite:exclude}
|
||||||
|
@keyframes rise{from{opacity:0;transform:translateY(14px) scale(.99)}to{opacity:1;transform:none}}
|
||||||
|
.d1{animation-delay:.04s}.d2{animation-delay:.12s}.d3{animation-delay:.2s}.d4{animation-delay:.28s}.d5{animation-delay:.36s}
|
||||||
|
|
||||||
|
label{display:block;font-size:11.5px;letter-spacing:.7px;text-transform:uppercase;color:var(--muted);margin-bottom:8px}
|
||||||
|
.fields{display:grid;grid-template-columns:repeat(2,1fr);gap:13px}
|
||||||
|
@media (min-width:680px){.fields{grid-template-columns:repeat(4,1fr)}}
|
||||||
|
input[type=number]{width:100%;padding:11px 12px;font-size:17px;font-weight:700;color:#fff;font-family:inherit;
|
||||||
|
background:rgba(8,12,24,.7);border:1px solid var(--stroke);border-radius:12px;
|
||||||
|
transition:border-color .25s, box-shadow .25s;
|
||||||
|
-moz-appearance:textfield;font-variant-numeric:tabular-nums}
|
||||||
|
input[type=number]::-webkit-outer-spin-button,
|
||||||
|
input[type=number]::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}
|
||||||
|
input[type=number]:focus{outline:none;border-color:rgba(34,211,238,.85);
|
||||||
|
box-shadow:0 0 0 4px rgba(34,211,238,.14), 0 0 24px -6px rgba(34,211,238,.75)}
|
||||||
|
|
||||||
|
/* ===== 分段选择(带滑动光柱) ===== */
|
||||||
|
.seg{position:relative;display:flex;gap:4px;padding:4px;border-radius:12px;
|
||||||
|
background:rgba(8,12,24,.7);border:1px solid var(--stroke)}
|
||||||
|
.seg .pill{position:absolute;left:4px;top:4px;bottom:4px;width:0;border-radius:9px;z-index:0;
|
||||||
|
background:linear-gradient(100deg,var(--c1),var(--c2));
|
||||||
|
box-shadow:0 0 24px -3px rgba(34,211,238,.75),0 0 40px -12px rgba(168,85,247,.9);
|
||||||
|
transition:transform .34s cubic-bezier(.4,1.35,.5,1), width .34s cubic-bezier(.4,1.35,.5,1)}
|
||||||
|
.seg button{flex:1;position:relative;z-index:1;border:0;background:transparent;color:var(--muted);
|
||||||
|
font:inherit;font-size:13px;padding:8px 6px;border-radius:9px;cursor:pointer;transition:color .25s}
|
||||||
|
.seg button.active{color:#05070f;font-weight:800}
|
||||||
|
|
||||||
|
/* ===== 滑块 ===== */
|
||||||
|
input[type=range]{-webkit-appearance:none;appearance:none;width:100%;height:8px;border-radius:999px;outline:none;
|
||||||
|
margin:12px 0 4px;cursor:pointer;
|
||||||
|
background:linear-gradient(90deg,var(--c1),var(--c2)) 0/var(--p,50%) 100% no-repeat,rgba(148,163,184,.18)}
|
||||||
|
input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:22px;height:22px;border:0;border-radius:50%;
|
||||||
|
background:radial-gradient(circle at 34% 30%,#fff,#22d3ee 58%,#0891b2);
|
||||||
|
box-shadow:0 0 0 4px rgba(34,211,238,.16),0 0 22px rgba(34,211,238,.9);transition:transform .15s}
|
||||||
|
input[type=range]::-webkit-slider-thumb:active{transform:scale(1.16)}
|
||||||
|
input[type=range]::-moz-range-thumb{width:20px;height:20px;border:0;border-radius:50%;
|
||||||
|
background:radial-gradient(circle at 34% 30%,#fff,#22d3ee 58%,#0891b2);
|
||||||
|
box-shadow:0 0 0 4px rgba(34,211,238,.16),0 0 22px rgba(34,211,238,.9)}
|
||||||
|
.row{display:flex;align-items:baseline;justify-content:space-between;gap:12px;flex-wrap:wrap}
|
||||||
|
.chip{font-size:12.5px;color:#bfe9ff;font-variant-numeric:tabular-nums;
|
||||||
|
border:1px solid rgba(34,211,238,.3);background:rgba(34,211,238,.1);padding:3px 10px;border-radius:999px}
|
||||||
|
|
||||||
|
/* ===== 大数字 ===== */
|
||||||
|
.big{font-size:clamp(34px,8.4vw,52px);font-weight:800;letter-spacing:-.6px;line-height:1.05;
|
||||||
|
font-variant-numeric:tabular-nums;
|
||||||
|
background:var(--neon);background-size:280% 100%;-webkit-background-clip:text;background-clip:text;
|
||||||
|
color:transparent;animation:flow 9s linear infinite;text-shadow:0 0 40px rgba(34,211,238,.18)}
|
||||||
|
.unit{font-size:13px;font-weight:500;color:var(--muted);margin-left:7px;-webkit-text-fill-color:var(--muted)}
|
||||||
|
.pill-tag{display:inline-block;font-size:12.5px;font-weight:700;padding:3px 12px;border-radius:999px;
|
||||||
|
margin-left:10px;vertical-align:middle;border:1px solid currentColor;background:rgba(255,255,255,.05)}
|
||||||
|
|
||||||
|
/* ===== BMI 色带 ===== */
|
||||||
|
.meter{position:relative;height:14px;border-radius:999px;overflow:hidden;display:flex;margin-top:18px;
|
||||||
|
box-shadow:inset 0 0 12px rgba(0,0,0,.75)}
|
||||||
|
.meter i{flex:1}
|
||||||
|
.meter .sweep{position:absolute;inset:0;pointer-events:none;
|
||||||
|
background:linear-gradient(90deg,transparent,rgba(255,255,255,.3),transparent);
|
||||||
|
animation:sweep 3.6s linear infinite}
|
||||||
|
@keyframes sweep{0%{transform:translateX(-100%)}100%{transform:translateX(100%)}}
|
||||||
|
.marker{position:absolute;top:-9px;width:18px;height:32px;transform:translateX(-50%);pointer-events:none;
|
||||||
|
transition:left .42s cubic-bezier(.4,1.3,.5,1)}
|
||||||
|
.marker::after{content:"";position:absolute;left:50%;top:50%;width:11px;height:11px;margin:-5.5px 0 0 -5.5px;
|
||||||
|
border-radius:50%;background:#fff;animation:pulse 2.1s ease-in-out infinite}
|
||||||
|
@keyframes pulse{
|
||||||
|
0%,100%{box-shadow:0 0 0 3px rgba(255,255,255,.28),0 0 18px 4px rgba(34,211,238,.95)}
|
||||||
|
50%{box-shadow:0 0 0 8px rgba(255,255,255,.07),0 0 28px 9px rgba(168,85,247,.95)}
|
||||||
|
}
|
||||||
|
.ticks{display:flex;justify-content:space-between;font-size:11px;color:#7c8bab;margin-top:6px;
|
||||||
|
font-variant-numeric:tabular-nums}
|
||||||
|
|
||||||
|
/* ===== 结果卡片 ===== */
|
||||||
|
.stats{display:grid;grid-template-columns:1fr;gap:14px;margin-bottom:16px}
|
||||||
|
@media (min-width:680px){.stats{grid-template-columns:1fr 1fr}}
|
||||||
|
.stat{position:relative;overflow:hidden;background:var(--glass);border:1px solid var(--stroke);border-radius:18px;
|
||||||
|
padding:16px 17px;backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);
|
||||||
|
box-shadow:0 18px 50px -34px rgba(0,0,0,.95), inset 0 1px 0 rgba(255,255,255,.05);
|
||||||
|
transition:transform .3s cubic-bezier(.2,.8,.3,1), box-shadow .3s, border-color .3s;
|
||||||
|
animation:rise .62s cubic-bezier(.2,.85,.3,1) both}
|
||||||
|
.stat:hover{transform:translateY(-4px);border-color:rgba(255,255,255,.22);
|
||||||
|
box-shadow:0 26px 60px -34px rgba(0,0,0,1), 0 0 34px -16px rgba(34,211,238,.55)}
|
||||||
|
.stat::after{content:"";position:absolute;left:0;top:0;bottom:0;width:3px;background:var(--acc,var(--c1));
|
||||||
|
box-shadow:0 0 18px 2px var(--acc,var(--c1))}
|
||||||
|
.stat .k{font-size:11.5px;letter-spacing:.7px;text-transform:uppercase;color:var(--muted);
|
||||||
|
margin-bottom:7px;display:flex;align-items:center;gap:8px}
|
||||||
|
.stat .dot{width:7px;height:7px;border-radius:50%;background:var(--acc,var(--c1));
|
||||||
|
box-shadow:0 0 10px 2px var(--acc,var(--c1))}
|
||||||
|
.stat .v{font-size:clamp(23px,4.6vw,29px);font-weight:800;font-variant-numeric:tabular-nums;
|
||||||
|
letter-spacing:-.3px;color:#fff}
|
||||||
|
.stat .v .unit{font-size:12px}
|
||||||
|
.stat .d{font-size:11.5px;color:var(--muted);margin-top:6px}
|
||||||
|
|
||||||
|
/* ===== 提示 ===== */
|
||||||
|
.alert{border-color:rgba(251,191,36,.4)!important;background:rgba(251,191,36,.08)!important;
|
||||||
|
color:#ffe9b8;font-size:13px}
|
||||||
|
.alert::before{background:linear-gradient(140deg,rgba(251,191,36,.6),rgba(244,114,182,.35) 45%,transparent 72%)!important}
|
||||||
|
.alert p{margin:0 0 7px}
|
||||||
|
.alert p:last-child{margin-bottom:0}
|
||||||
|
.alert b{color:#fff}
|
||||||
|
|
||||||
|
/* ===== 算法 ===== */
|
||||||
|
h2{font-size:14px;margin:0 0 12px;letter-spacing:.5px;color:#dbe6ff;font-weight:700}
|
||||||
|
ol{padding-left:20px;font-size:13px;color:#c3cfe6;margin:0}
|
||||||
|
ol li{margin-bottom:6px}
|
||||||
|
code{background:rgba(34,211,238,.12);border:1px solid rgba(34,211,238,.22);color:#a5f3fc;
|
||||||
|
padding:1px 6px;border-radius:6px;font-size:12px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace}
|
||||||
|
.foot{font-size:11.5px;color:#6f7d9b;line-height:1.8;margin:6px 2px 0}
|
||||||
|
.foot b{color:#9fb0d0}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion:reduce){
|
||||||
|
*{animation:none!important;transition:none!important}
|
||||||
}
|
}
|
||||||
* { box-sizing:border-box; }
|
|
||||||
body { margin:0; padding:24px 16px; background:var(--bg); color:var(--text); line-height:1.6;
|
|
||||||
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif; }
|
|
||||||
main { max-width:760px; margin:0 auto; }
|
|
||||||
h1 { font-size:22px; margin:0 0 6px; }
|
|
||||||
h2 { font-size:15px; margin:0 0 10px; }
|
|
||||||
.sub { color:var(--muted); font-size:13px; margin:0 0 18px; }
|
|
||||||
.card { background:var(--card); border:1px solid var(--line); border-radius:14px; padding:16px; margin-bottom:14px; }
|
|
||||||
.grid { display:grid; grid-template-columns:repeat(2,1fr); gap:12px; }
|
|
||||||
@media (min-width:640px) { .grid { grid-template-columns:repeat(4,1fr); } }
|
|
||||||
.field > label { display:block; font-size:12px; color:var(--muted); margin-bottom:6px; }
|
|
||||||
input[type=number] { width:100%; padding:9px 10px; font-size:15px; color:var(--text);
|
|
||||||
border:1px solid var(--line); border-radius:9px; background:#fff; }
|
|
||||||
input[type=number]:focus { outline:none; border-color:var(--emerald); }
|
|
||||||
input[type=range] { width:100%; accent-color:var(--emerald); }
|
|
||||||
.seg { display:flex; background:#eef1f4; border-radius:9px; padding:3px; }
|
|
||||||
.seg-btn { flex:1; padding:7px 4px; font-size:13px; border:0; border-radius:7px; cursor:pointer;
|
|
||||||
background:transparent; color:var(--muted); font-family:inherit; }
|
|
||||||
.seg-btn.active { background:#fff; color:var(--text); font-weight:600; box-shadow:0 1px 2px rgba(0,0,0,.08); }
|
|
||||||
.mt { margin-top:12px; }
|
|
||||||
.cards { display:grid; grid-template-columns:1fr; gap:12px; margin-bottom:14px; }
|
|
||||||
@media (min-width:640px) { .cards { grid-template-columns:1fr 1fr; } }
|
|
||||||
.stat { background:var(--card); border:1px solid var(--line); border-radius:14px; padding:14px 16px; }
|
|
||||||
.stat .t { font-size:12px; color:var(--muted); margin-bottom:4px; }
|
|
||||||
.stat .v { font-size:24px; font-weight:700; }
|
|
||||||
.stat .v small { font-size:12px; font-weight:400; color:var(--muted); margin-left:4px; }
|
|
||||||
.stat .s { font-size:12px; color:var(--muted); margin-top:4px; }
|
|
||||||
.bar { position:relative; height:12px; border-radius:999px; overflow:hidden; display:flex; margin-top:14px; }
|
|
||||||
.bar i { flex:1; }
|
|
||||||
.bar .mk { position:absolute; top:-4px; width:4px; height:20px; border-radius:2px; background:#111827; transform:translateX(-50%); }
|
|
||||||
.ticks { display:flex; justify-content:space-between; font-size:11px; color:#9ca3af; margin-top:4px; }
|
|
||||||
.warn { background:#fffbeb; border-color:#fde68a; color:#92400e; font-size:13px; }
|
|
||||||
.warn p { margin:0 0 6px; }
|
|
||||||
.warn p:last-child { margin-bottom:0; }
|
|
||||||
.muted { font-size:12px; color:var(--muted); }
|
|
||||||
ol { padding-left:20px; font-size:13px; color:#374151; margin:0; }
|
|
||||||
ol li { margin-bottom:4px; }
|
|
||||||
code { background:#f3f4f6; padding:1px 5px; border-radius:5px; font-size:12px; }
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<div class="aurora" aria-hidden="true"><i></i><i></i><i></i><i></i></div>
|
||||||
<h1>BMI 与每日热量计算器</h1>
|
<div class="mesh" aria-hidden="true"></div>
|
||||||
<p class="sub">输入性别、年龄、身高、体重与每日步数,即时得到 BMR、活动系数 PAL、每日总消耗 TDEE 与建议摄入热量。单文件、无需联网。</p>
|
|
||||||
|
|
||||||
<section class="card">
|
<main>
|
||||||
<div class="grid">
|
<h1>BMI 与每日热量 <span class="neon">计算器</span></h1>
|
||||||
<div class="field">
|
<p class="sub">输入性别、年龄、身高、体重与每日步数,实时得到基础代谢、活动系数、每日总消耗与建议摄入热量。</p>
|
||||||
|
<div class="badges">
|
||||||
|
<span class="badge"><b>Mifflin-St Jeor</b> + <b>Schofield</b> 取平均</span>
|
||||||
|
<span class="badge">步数 → <b>PAL</b> 自动换算</span>
|
||||||
|
<span class="badge">青少年走 <b>WS/T 586-2018</b></span>
|
||||||
|
<span class="badge">单文件 · 离线可用</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section class="panel d1">
|
||||||
|
<div class="fields">
|
||||||
|
<div>
|
||||||
<label>性别</label>
|
<label>性别</label>
|
||||||
<div class="seg" id="sexSeg">
|
<div class="seg" id="sexSeg">
|
||||||
|
<span class="pill"></span>
|
||||||
<button class="seg-btn" data-sex="male">男</button>
|
<button class="seg-btn" data-sex="male">男</button>
|
||||||
<button class="seg-btn active" data-sex="female">女</button>
|
<button class="seg-btn active" data-sex="female">女</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="field"><label>年龄(岁)</label>
|
<div><label>年龄 · 岁</label><input id="age" type="number" min="6" max="120" step="1" value="30" /></div>
|
||||||
<input id="age" type="number" min="6" max="120" step="1" value="30" /></div>
|
<div><label>身高 · cm</label><input id="height" type="number" min="100" max="220" step="1" value="165" /></div>
|
||||||
<div class="field"><label>身高(cm)</label>
|
<div><label>体重 · kg</label><input id="weight" type="number" min="20" max="200" step="0.1" value="55" /></div>
|
||||||
<input id="height" type="number" min="100" max="220" step="1" value="165" /></div>
|
|
||||||
<div class="field"><label>体重(kg)</label>
|
|
||||||
<input id="weight" type="number" min="20" max="200" step="0.1" value="55" /></div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field mt">
|
<div style="margin-top:16px">
|
||||||
<label>每日步数 — <span id="stepsOut">10000 步 · 活动系数 1.60</span></label>
|
<div class="row">
|
||||||
|
<label style="margin:0">每日步数</label>
|
||||||
|
<span class="chip" id="stepsOut">10000 步 · PAL 1.60</span>
|
||||||
|
</div>
|
||||||
<input id="steps" type="range" min="2000" max="20000" step="500" value="10000" />
|
<input id="steps" type="range" min="2000" max="20000" step="500" value="10000" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="field mt">
|
<div style="margin-top:16px">
|
||||||
<label>目标</label>
|
<label>目标</label>
|
||||||
<div class="seg" id="goalSeg">
|
<div class="seg" id="goalSeg">
|
||||||
|
<span class="pill"></span>
|
||||||
<button class="seg-btn active" data-goal="maintain">维持体重</button>
|
<button class="seg-btn active" data-goal="maintain">维持体重</button>
|
||||||
<button class="seg-btn" data-goal="gain">增重</button>
|
<button class="seg-btn" data-goal="gain">增重</button>
|
||||||
<button class="seg-btn" data-goal="cut">减重</button>
|
<button class="seg-btn" data-goal="cut">减重</button>
|
||||||
@@ -86,35 +226,64 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="card" id="bmiCard">
|
<section class="panel d2">
|
||||||
<div style="padding:0">
|
<label>BMI · 身体质量指数</label>
|
||||||
<div class="t" style="font-size:12px;color:var(--muted);margin-bottom:4px">BMI(身体质量指数)</div>
|
<div>
|
||||||
<div class="v" style="font-size:24px;font-weight:700"><span id="bmiVal">—</span> <small id="bmiClass" style="font-size:12px;font-weight:400;margin-left:4px"></small></div>
|
<span class="big" id="bmiVal">—</span><span class="unit">kg/m²</span>
|
||||||
<div class="s" id="bmiScaleNote" style="font-size:12px;color:var(--muted);margin-top:4px"></div>
|
<span class="pill-tag" id="bmiClass"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="bar">
|
<div class="meter">
|
||||||
<i style="background:#7dd3fc"></i><i style="background:#6ee7b7"></i>
|
<i style="background:linear-gradient(90deg,#0ea5e9,#38bdf8)"></i>
|
||||||
<i style="background:#fcd34d"></i><i style="background:#fda4af"></i>
|
<i style="background:linear-gradient(90deg,#34d399,#10b981)"></i>
|
||||||
<span class="mk" id="bmiMarker" style="left:0%"></span>
|
<i style="background:linear-gradient(90deg,#fbbf24,#f59e0b)"></i>
|
||||||
|
<i style="background:linear-gradient(90deg,#fb7185,#e11d48)"></i>
|
||||||
|
<span class="sweep"></span>
|
||||||
|
<span class="marker" id="bmiMarker" style="left:0%"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="ticks"><span>13</span><span>18.5</span><span>24</span><span>28</span><span>30</span></div>
|
<div class="ticks"><span>13</span><span>18.5</span><span>24</span><span>28</span><span>30</span></div>
|
||||||
|
<div class="sub" style="margin:12px 0 0;font-size:12px" id="bmiScaleNote"></div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="cards" id="cards"></section>
|
<section class="stats">
|
||||||
<section class="card warn" id="warn" hidden></section>
|
<div class="stat d2" style="--acc:#22d3ee">
|
||||||
|
<div class="k"><span class="dot"></span>基础代谢 BMR</div>
|
||||||
|
<div class="v"><span id="vBMR">0</span><span class="unit">kcal/天</span></div>
|
||||||
|
<div class="d" id="sBMR"></div>
|
||||||
|
</div>
|
||||||
|
<div class="stat d3" style="--acc:#a855f7">
|
||||||
|
<div class="k"><span class="dot"></span>每日总消耗 TDEE</div>
|
||||||
|
<div class="v"><span id="vTDEE">0</span><span class="unit">kcal/天</span></div>
|
||||||
|
<div class="d" id="sTDEE"></div>
|
||||||
|
</div>
|
||||||
|
<div class="stat d4" style="--acc:#f472b6">
|
||||||
|
<div class="k"><span class="dot"></span>建议每日摄入</div>
|
||||||
|
<div class="v"><span id="vLo">0</span><span class="unit" id="uTilde">~</span><span id="vHi">0</span><span class="unit">kcal/天</span></div>
|
||||||
|
<div class="d" id="sGoal"></div>
|
||||||
|
</div>
|
||||||
|
<div class="stat d5" style="--acc:#34d399">
|
||||||
|
<div class="k"><span class="dot"></span>参考目标体重 · BMI 20~21</div>
|
||||||
|
<div class="v" id="vTW">—</div>
|
||||||
|
<div class="d" id="sTW"></div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section class="card">
|
<section class="panel alert d5" id="warn" hidden></section>
|
||||||
|
|
||||||
|
<section class="panel d5">
|
||||||
<h2>算法说明</h2>
|
<h2>算法说明</h2>
|
||||||
<ol>
|
<ol>
|
||||||
<li><b>BMI</b> = 体重(kg) ÷ (身高(m))²;成人分类:偏瘦 <18.5,正常 18.5~24,超重 24~28,肥胖 ≥28。未满 18 岁不套此阈值,须用年龄别百分位(WS/T 586-2018)。</li>
|
<li><b>BMI</b> = 体重(kg) ÷ 身高(m)²;成人分类:偏瘦 <18.5,正常 18.5~24,超重 24~28,肥胖 ≥28。未满 18 岁不套此阈值,须用年龄别百分位(WS/T 586-2018)。</li>
|
||||||
<li><b>BMR</b> 取两个公式的平均:Mifflin-St Jeor(<code>10W + 6.25H − 5A + 男5/女−161</code>)与 Schofield(男 <code>15.3W+679</code>、女 <code>14.7W+496</code>,18 岁以下另用青少年系数)。</li>
|
<li><b>BMR</b> 取两式平均:Mifflin-St Jeor <code>10W + 6.25H − 5A + 男5/女−161</code>,Schofield 男 <code>15.3W+679</code>、女 <code>14.7W+496</code>(18 岁以下用青少年系数)。</li>
|
||||||
<li><b>PAL</b> 由步数换算:<code>1.2 + 步数/1000 × 0.04</code>,上限 1.95;分档区间 <code><5000→1.15~1.25</code>、<code>10000~→1.50~1.60</code>、<code>≥12500→1.60~1.80</code>。每天 1 万步 ≈ 1.60。</li>
|
<li><b>PAL</b> 由步数换算:<code>1.2 + 步数/1000 × 0.04</code>,上限 1.95;分档 <code><5000→1.15~1.25</code>、<code>10000~→1.50~1.60</code>、<code>≥12500→1.60~1.80</code>。每天 1 万步 ≈ <code>1.60</code>。</li>
|
||||||
<li><b>TDEE</b> = BMR × PAL。</li>
|
<li><b>TDEE</b> = BMR × PAL。</li>
|
||||||
<li><b>目标摄入</b>:维持 = TDEE;增重 = TDEE + 300~500;减重 = TDEE × 0.825,且不低于 BMR 与安全下限(男 1500 / 女 1200 kcal)。</li>
|
<li><b>目标摄入</b>:维持 = TDEE;增重 = TDEE + 300~500;减重 = TDEE × 0.825,且不低于 BMR 与安全下限(男 1500 / 女 1200 kcal)。</li>
|
||||||
</ol>
|
</ol>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<p class="muted">步数只能粗略估计活动量(快走/慢走可差 ±15%),请把结果当作起始值,执行 2~3 周后按体重趋势微调 ±100~200 kcal。本工具仅作健康科普参考,不构成医疗建议。</p>
|
<p class="foot">
|
||||||
|
<b>提示:</b>步数只能粗略估计活动量(快走/慢走可差 ±15%),请把结果当作起始值,执行 2~3 周后按体重趋势微调 ±100~200 kcal。<br />
|
||||||
|
本工具仅作健康科普参考,不构成医疗建议。若体重持续下降或伴乏力、脱发,请咨询医生或注册营养师。
|
||||||
|
</p>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -123,16 +292,32 @@
|
|||||||
|
|
||||||
var state = { sex: 'female', steps: 10000, goal: 'maintain' };
|
var state = { sex: 'female', steps: 10000, goal: 'maintain' };
|
||||||
var $ = function (id) { return document.getElementById(id); };
|
var $ = function (id) { return document.getElementById(id); };
|
||||||
var r0 = function (n) { return Math.round(n).toLocaleString('en-US'); };
|
|
||||||
var clamp = function (v, lo, hi) { return Math.min(hi, Math.max(lo, v)); };
|
var clamp = function (v, lo, hi) { return Math.min(hi, Math.max(lo, v)); };
|
||||||
|
var fmt = function (v, d) { return d ? v.toFixed(d) : Math.round(v).toLocaleString('en-US'); };
|
||||||
|
|
||||||
|
/* ---------- 数字滚动动画 ---------- */
|
||||||
|
function animateNum(el, to, decimals) {
|
||||||
|
if (el._raf) cancelAnimationFrame(el._raf);
|
||||||
|
var from = typeof el._val === 'number' ? el._val : to;
|
||||||
|
el._val = to;
|
||||||
|
if (from === to) { el.textContent = fmt(to, decimals); return; }
|
||||||
|
var t0 = null, dur = 320;
|
||||||
|
function step(ts) {
|
||||||
|
if (t0 === null) t0 = ts;
|
||||||
|
var p = Math.min(1, (ts - t0) / dur);
|
||||||
|
var e = 1 - Math.pow(1 - p, 3);
|
||||||
|
el.textContent = fmt(from + (to - from) * e, decimals);
|
||||||
|
if (p < 1) el._raf = requestAnimationFrame(step);
|
||||||
|
}
|
||||||
|
el._raf = requestAnimationFrame(step);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- 算法 ---------- */
|
||||||
function num(id, fallback) {
|
function num(id, fallback) {
|
||||||
var v = parseFloat($(id).value);
|
var v = parseFloat($(id).value);
|
||||||
return isFinite(v) ? v : fallback;
|
return isFinite(v) ? v : fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
function palFromSteps(steps) { return clamp(1.2 + (steps / 1000) * 0.04, 1.2, 1.95); }
|
function palFromSteps(steps) { return clamp(1.2 + (steps / 1000) * 0.04, 1.2, 1.95); }
|
||||||
|
|
||||||
function palBucket(steps) {
|
function palBucket(steps) {
|
||||||
if (steps < 5000) return [1.15, 1.25];
|
if (steps < 5000) return [1.15, 1.25];
|
||||||
if (steps < 7500) return [1.30, 1.45];
|
if (steps < 7500) return [1.30, 1.45];
|
||||||
@@ -140,13 +325,12 @@
|
|||||||
if (steps < 12500) return [1.50, 1.60];
|
if (steps < 12500) return [1.50, 1.60];
|
||||||
return [1.60, 1.80];
|
return [1.60, 1.80];
|
||||||
}
|
}
|
||||||
|
|
||||||
function bmiClassOf(bmi, age) {
|
function bmiClassOf(bmi, age) {
|
||||||
if (age < 18) return { label: '未成年人(请用年龄别百分位判定)', color: 'var(--muted)' };
|
if (age > 0 && age < 18) return { label: '未成年', color: '#94a3b8' };
|
||||||
if (bmi < 18.5) return { label: '偏瘦', color: 'var(--sky)' };
|
if (bmi < 18.5) return { label: '偏瘦', color: '#38bdf8' };
|
||||||
if (bmi < 24) return { label: '正常', color: 'var(--emerald)' };
|
if (bmi < 24) return { label: '正常', color: '#34d399' };
|
||||||
if (bmi < 28) return { label: '超重', color: 'var(--amber)' };
|
if (bmi < 28) return { label: '超重', color: '#fbbf24' };
|
||||||
return { label: '肥胖', color: 'var(--rose)' };
|
return { label: '肥胖', color: '#fb7185' };
|
||||||
}
|
}
|
||||||
|
|
||||||
function compute() {
|
function compute() {
|
||||||
@@ -160,15 +344,11 @@
|
|||||||
: (age < 18 ? 13.4 * weight + 692 : 14.7 * weight + 496);
|
: (age < 18 ? 13.4 * weight + 692 : 14.7 * weight + 496);
|
||||||
var bmr = (mifflin + schofield) / 2;
|
var bmr = (mifflin + schofield) / 2;
|
||||||
|
|
||||||
var pal = palFromSteps(state.steps);
|
var pal = palFromSteps(state.steps), b = palBucket(state.steps), tdee = bmr * pal;
|
||||||
var b = palBucket(state.steps);
|
|
||||||
var tdee = bmr * pal;
|
|
||||||
|
|
||||||
var lo, hi, goalDesc;
|
var lo, hi, goalDesc;
|
||||||
if (state.goal === 'maintain') { lo = hi = tdee; goalDesc = '维持体重'; }
|
if (state.goal === 'maintain') { lo = hi = tdee; goalDesc = '维持体重'; }
|
||||||
else if (state.goal === 'gain') {
|
else if (state.goal === 'gain') { lo = tdee + 300; hi = tdee + 500; goalDesc = '健康增重(每日 +300~500 kcal)'; }
|
||||||
lo = tdee + 300; hi = tdee + 500; goalDesc = '健康增重(每日 +300~500 kcal)';
|
else {
|
||||||
} else {
|
|
||||||
var floor = state.sex === 'male' ? 1500 : 1200;
|
var floor = state.sex === 'male' ? 1500 : 1200;
|
||||||
lo = hi = Math.max(tdee * 0.825, bmr, floor);
|
lo = hi = Math.max(tdee * 0.825, bmr, floor);
|
||||||
goalDesc = '减重(约 −17.5%,不低于 BMR 与安全下限)';
|
goalDesc = '减重(约 −17.5%,不低于 BMR 与安全下限)';
|
||||||
@@ -176,56 +356,58 @@
|
|||||||
|
|
||||||
var protLo = (age < 20 ? 1.5 : 1.2) * weight;
|
var protLo = (age < 20 ? 1.5 : 1.2) * weight;
|
||||||
var protHi = (age < 20 ? 1.8 : 1.6) * weight;
|
var protHi = (age < 20 ? 1.8 : 1.6) * weight;
|
||||||
var w20 = 20 * hm * hm, w21 = 21 * hm * hm;
|
return {
|
||||||
|
bmi: bmi, age: age, height: height, weight: weight, hm: hm,
|
||||||
return { bmi: bmi, age: age, weight: weight, bmr: bmr, mifflin: mifflin,
|
bmr: bmr, mifflin: mifflin, schofield: schofield, pal: pal, bucket: b, tdee: tdee,
|
||||||
schofield: schofield, pal: pal, bucket: b, tdee: tdee, intakeLo: lo, intakeHi: hi,
|
intakeLo: lo, intakeHi: hi, goalDesc: goalDesc, protLo: protLo, protHi: protHi,
|
||||||
goalDesc: goalDesc, protLo: protLo, protHi: protHi, w20: w20, w21: w21 };
|
w20: 20 * hm * hm, w21: 21 * hm * hm
|
||||||
}
|
};
|
||||||
|
|
||||||
function card(title, value, unit, sub) {
|
|
||||||
return '<div class="stat"><div class="t">' + title + '</div>' +
|
|
||||||
'<div class="v">' + value + (unit ? '<small>' + unit + '</small>' : '') + '</div>' +
|
|
||||||
(sub ? '<div class="s">' + sub + '</div>' : '') + '</div>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ---------- 渲染 ---------- */
|
||||||
function render() {
|
function render() {
|
||||||
var r = compute();
|
var r = compute(), cls = bmiClassOf(r.bmi, r.age);
|
||||||
var cls = bmiClassOf(r.bmi, r.age);
|
|
||||||
|
|
||||||
$('bmiVal').textContent = r.bmi > 0 ? r.bmi.toFixed(1) : '—';
|
if (r.bmi > 0) { animateNum($('bmiVal'), r.bmi, 1); }
|
||||||
$('bmiClass').textContent = '→ ' + cls.label;
|
else { $('bmiVal').textContent = '—'; $('bmiVal')._val = undefined; }
|
||||||
$('bmiClass').style.color = cls.color;
|
|
||||||
$('bmiScaleNote').textContent = r.age < 18
|
var tag = $('bmiClass');
|
||||||
|
tag.textContent = cls.label;
|
||||||
|
tag.style.color = cls.color;
|
||||||
|
tag.style.boxShadow = '0 0 22px -8px ' + cls.color;
|
||||||
|
$('bmiMarker').style.left = clamp((r.bmi - 13) / (30 - 13) * 100, 0, 100) + '%';
|
||||||
|
$('bmiScaleNote').textContent = (r.age > 0 && r.age < 18)
|
||||||
? '未满 18 岁:成人阈值 18.5 / 24 / 28 不适用,请用年龄别 BMI 百分位(WS/T 586-2018)判定。'
|
? '未满 18 岁:成人阈值 18.5 / 24 / 28 不适用,请用年龄别 BMI 百分位(WS/T 586-2018)判定。'
|
||||||
: '成人参考:偏瘦 < 18.5,正常 18.5~24,超重 24~28,肥胖 ≥ 28。';
|
: '成人参考:偏瘦 < 18.5,正常 18.5~24,超重 24~28,肥胖 ≥ 28。';
|
||||||
$('bmiMarker').style.left = clamp((r.bmi - 13) / (30 - 13) * 100, 0, 100) + '%';
|
|
||||||
|
|
||||||
$('stepsOut').textContent = state.steps.toLocaleString('en-US') + ' 步 · 活动系数 ' + r.pal.toFixed(2);
|
$('stepsOut').textContent = state.steps.toLocaleString('en-US') + ' 步 · PAL ' + r.pal.toFixed(2);
|
||||||
|
|
||||||
var intakeText = Math.abs(r.intakeHi - r.intakeLo) < 1
|
animateNum($('vBMR'), r.bmr, 0);
|
||||||
? r0(r.intakeLo) : r0(r.intakeLo) + ' ~ ' + r0(r.intakeHi);
|
$('sBMR').textContent = 'Mifflin ' + fmt(r.mifflin) + ' · Schofield ' + fmt(r.schofield) + '(取平均)';
|
||||||
|
|
||||||
$('cards').innerHTML =
|
animateNum($('vTDEE'), r.tdee, 0);
|
||||||
card('基础代谢 BMR', r0(r.bmr), 'kcal/天',
|
$('sTDEE').textContent = 'PAL ' + r.pal.toFixed(2) + '(分档 ' + r.bucket[0].toFixed(2) + '~' + r.bucket[1].toFixed(2) +
|
||||||
'Mifflin ' + r0(r.mifflin) + ' · Schofield ' + r0(r.schofield) + '(取平均)') +
|
')|合理区间 ' + fmt(r.bmr * r.bucket[0]) + '~' + fmt(r.bmr * r.bucket[1]);
|
||||||
card('每日总消耗 TDEE', r0(r.tdee), 'kcal/天',
|
|
||||||
'PAL ' + r.pal.toFixed(2) + '(分档约 ' + r.bucket[0].toFixed(2) + '~' + r.bucket[1].toFixed(2) +
|
var single = Math.abs(r.intakeHi - r.intakeLo) < 1;
|
||||||
')|合理区间 ' + r0(r.bmr * r.bucket[0]) + '~' + r0(r.bmr * r.bucket[1])) +
|
animateNum($('vLo'), single ? r.intakeLo : r.intakeLo, 0);
|
||||||
card('建议每日摄入', intakeText, 'kcal/天', '目标:' + r.goalDesc) +
|
animateNum($('vHi'), r.intakeHi, 0);
|
||||||
card('参考目标体重(BMI 20~21)', r.w20.toFixed(1) + ' ~ ' + r.w21.toFixed(1), 'kg',
|
$('uTilde').style.display = single ? 'none' : 'inline';
|
||||||
(r.w21 - r.weight > 0.05
|
$('vHi').style.display = single ? 'none' : 'inline';
|
||||||
|
$('sGoal').textContent = '目标:' + r.goalDesc;
|
||||||
|
|
||||||
|
$('vTW').textContent = r.w20.toFixed(1) + ' ~ ' + r.w21.toFixed(1) + ' kg';
|
||||||
|
$('sTW').textContent = (r.w21 - r.weight > 0.05
|
||||||
? '还需增重 ' + Math.max(0, r.w20 - r.weight).toFixed(1) + ' ~ ' + (r.w21 - r.weight).toFixed(1) + ' kg'
|
? '还需增重 ' + Math.max(0, r.w20 - r.weight).toFixed(1) + ' ~ ' + (r.w21 - r.weight).toFixed(1) + ' kg'
|
||||||
: '体重已在目标区间内') +
|
: '体重已在目标区间内') + '|蛋白质 ' + fmt(r.protLo) + '~' + fmt(r.protHi) + ' g/天';
|
||||||
'|蛋白质 ' + r0(r.protLo) + '~' + r0(r.protHi) + ' g/天');
|
|
||||||
|
|
||||||
var msgs = [];
|
var msgs = [];
|
||||||
if (r.age < 18) {
|
if (r.age > 0 && r.age < 18) {
|
||||||
msgs.push('<p><b>未满 18 岁</b>:成人 BMI 阈值不适用,请用年龄别百分位判定,并让医生用 EER 青少年公式复核热量需求。</p>');
|
msgs.push('<p><b>未满 18 岁</b>:成人 BMI 阈值不适用,请用年龄别百分位判定,并让医生用 EER 青少年公式复核热量需求。</p>');
|
||||||
}
|
}
|
||||||
if (r.bmi > 0 && r.bmi < 20 && r.age >= 18) {
|
if (r.bmi > 0 && r.bmi < 20 && r.age >= 18) {
|
||||||
msgs.push('<p><b>你的 BMI 贴近偏瘦边缘</b>:目标可设在 BMI 20~21(体重 ' + r.w20.toFixed(1) + '~' + r.w21.toFixed(1) +
|
msgs.push('<p><b>你的 BMI 贴近偏瘦边缘</b>:目标可设在 BMI 20~21(体重 ' + r.w20.toFixed(1) + '~' + r.w21.toFixed(1) +
|
||||||
' kg),建议按 TDEE +300~500 kcal 吃,不要按减重口径进食。</p>');
|
' kg)。建议按 TDEE +300~500 kcal 吃,不要按减重口径进食。</p>');
|
||||||
}
|
}
|
||||||
if (state.goal === 'cut' && r.bmi > 0 && r.bmi < 18.5) {
|
if (state.goal === 'cut' && r.bmi > 0 && r.bmi < 18.5) {
|
||||||
msgs.push('<p>当前 BMI 已低于 18.5,不建议减重。</p>');
|
msgs.push('<p>当前 BMI 已低于 18.5,不建议减重。</p>');
|
||||||
@@ -234,23 +416,50 @@
|
|||||||
if (msgs.length) { warn.innerHTML = msgs.join(''); warn.hidden = false; } else { warn.hidden = true; }
|
if (msgs.length) { warn.innerHTML = msgs.join(''); warn.hidden = false; } else { warn.hidden = true; }
|
||||||
}
|
}
|
||||||
|
|
||||||
$('sexSeg').addEventListener('click', function (e) {
|
/* ---------- 分段选择的滑动光柱 ---------- */
|
||||||
var btn = e.target.closest('[data-sex]'); if (!btn) return;
|
function movePill(seg) {
|
||||||
state.sex = btn.dataset.sex;
|
var active = seg.querySelector('.seg-btn.active'), pill = seg.querySelector('.pill');
|
||||||
Array.prototype.forEach.call(this.children, function (c) { c.classList.toggle('active', c === btn); });
|
if (!active || !pill) return;
|
||||||
|
var sr = seg.getBoundingClientRect(), ar = active.getBoundingClientRect();
|
||||||
|
pill.style.width = ar.width + 'px';
|
||||||
|
pill.style.transform = 'translateX(' + (ar.left - sr.left - 4) + 'px)';
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindSeg(segId, key, attr) {
|
||||||
|
var seg = $(segId);
|
||||||
|
seg.addEventListener('click', function (e) {
|
||||||
|
var btn = e.target.closest('[' + attr + ']');
|
||||||
|
if (!btn) return;
|
||||||
|
state[key] = btn.getAttribute(attr);
|
||||||
|
Array.prototype.forEach.call(seg.querySelectorAll('.seg-btn'), function (c) {
|
||||||
|
c.classList.toggle('active', c === btn);
|
||||||
|
});
|
||||||
|
movePill(seg);
|
||||||
render();
|
render();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$('goalSeg').addEventListener('click', function (e) {
|
/* ---------- 事件绑定 ---------- */
|
||||||
var btn = e.target.closest('[data-goal]'); if (!btn) return;
|
bindSeg('sexSeg', 'sex', 'data-sex');
|
||||||
state.goal = btn.dataset.goal;
|
bindSeg('goalSeg', 'goal', 'data-goal');
|
||||||
Array.prototype.forEach.call(this.children, function (c) { c.classList.toggle('active', c === btn); });
|
|
||||||
render();
|
var stepsEl = $('steps');
|
||||||
|
function paintSlider() {
|
||||||
|
var p = (Number(stepsEl.value) - Number(stepsEl.min)) / (Number(stepsEl.max) - Number(stepsEl.min)) * 100;
|
||||||
|
stepsEl.style.setProperty('--p', p.toFixed(2) + '%');
|
||||||
|
}
|
||||||
|
stepsEl.addEventListener('input', function () {
|
||||||
|
state.steps = Number(this.value); paintSlider(); render();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('steps').addEventListener('input', function () { state.steps = Number(this.value); render(); });
|
|
||||||
['age', 'height', 'weight'].forEach(function (id) { $(id).addEventListener('input', render); });
|
['age', 'height', 'weight'].forEach(function (id) { $(id).addEventListener('input', render); });
|
||||||
|
|
||||||
|
function layout() {
|
||||||
|
movePill($('sexSeg')); movePill($('goalSeg')); paintSlider();
|
||||||
|
}
|
||||||
|
window.addEventListener('resize', layout);
|
||||||
|
window.addEventListener('load', layout);
|
||||||
|
|
||||||
|
layout();
|
||||||
render();
|
render();
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user