demo-static-web / index.html
waveshaker's picture
Update index.html
ab423a8 verified
Raw History Blame Contribute Delete
2.36 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Static UI Lab</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- 顶部 Header -->
<header>
<h1>Static UI Lab</h1>
<p>Front-end testing environment</p>
</header>
<!-- 顶部 Tab 导航栏 -->
<div class="tab-nav">
<button class="tab-btn active" onclick="switchTab(event, 'demo1')">Demo 1: Basic</button>
<button class="tab-btn" onclick="switchTab(event, 'demo2')">Demo 2: Advanced</button>
<button class="tab-btn" onclick="switchTab(event, 'demo3')">Demo 3: API</button>
<button class="tab-btn" onclick="switchTab(event, 'demo4')">Demo 4: Shader</button>
</div>
<!-- 内容区:包含多个 iframe,每个 iframe 完全隔离 -->
<div class="tab-content">
<!-- Demo 1 默认加载 -->
<iframe id="frame-demo1" class="demo-frame active" src="./demos/demo1/index.html"></iframe>
<!-- Demo 2 和 3 使用 data-src 延迟加载(按需加载) -->
<iframe id="frame-demo2" class="demo-frame" data-src="./demos/demo2/index.html"></iframe>
<iframe id="frame-demo3" class="demo-frame" data-src="./demos/demo3/index.html"></iframe>
<iframe id="frame-demo4" class="demo-frame" data-src="./demos/demo4/index.html"></iframe>
</div>
<script>
function switchTab(evt, demoId) {
// 1. 获取所有的 Tab 按钮,并移除 active 状态
const tabs = document.querySelectorAll(".tab-btn");
tabs.forEach(t => t.classList.remove("active"));
evt.currentTarget.classList.add("active");
// 2. 获取所有的 iframe,并隐藏
const frames = document.querySelectorAll(".demo-frame");
frames.forEach(f => f.classList.remove("active"));
// 3. 显示目标 iframe
const targetFrame = document.getElementById(`frame-${demoId}`);
targetFrame.classList.add("active");
// 4. 核心逻辑:按需加载
// 如果该 iframe 有 data-src 属性(即尚未加载),则将其赋给 src 触发请求
if (targetFrame.dataset.src && !targetFrame.src) {
targetFrame.src = targetFrame.dataset.src;
}
}
</script>
</body>
</html>