211 lines
7.5 KiB
HTML
211 lines
7.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>目录</title>
|
|
<style>
|
|
*{
|
|
margin: 0 0;
|
|
padding: 0 0;
|
|
}
|
|
#big_box{
|
|
width: 100vw;
|
|
display: flex;
|
|
flex-direction: column;
|
|
flex-wrap: nowrap;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
.one_box{
|
|
width: 95vw;
|
|
text-align: center;
|
|
min-height: 10vw;
|
|
line-height: 10vw;
|
|
border: 2px solid wheat;
|
|
display: flex;
|
|
flex-direction: column;
|
|
flex-wrap: nowrap;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
.two_box{
|
|
width: 90vw;
|
|
text-align: center;
|
|
min-height: 10vw;
|
|
line-height: 10vw;
|
|
border: 2px solid coral;
|
|
}
|
|
.child_div{
|
|
width: 100%;
|
|
text-align: center;
|
|
height: 10vw;
|
|
line-height: 10vw;
|
|
background-color: darkgray;
|
|
}
|
|
img{
|
|
display: block;
|
|
width: 100%;
|
|
}
|
|
a{
|
|
width: 100vw;
|
|
text-align: center;
|
|
line-height: 10vw;
|
|
}
|
|
/* 添加的折叠样式 */
|
|
.one_box_c {
|
|
overflow: hidden;
|
|
height: 0;
|
|
transition: height 0.3s ease;
|
|
}
|
|
.two_box_c {
|
|
overflow: hidden;
|
|
height: 0;
|
|
transition: height 0.3s ease;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="big_box">
|
|
<div class="one_box">
|
|
<div class="one_box_t">0~6岁宝宝辅食</div>
|
|
<div class="one_box_c">
|
|
<div class="two_box">
|
|
<div class="two_box_t">01-宝宝辅食(文档)</div>
|
|
<div class="two_box_c">
|
|
<div class="child_div">1岁3个月宝宝辅食.doc</div>
|
|
</div>
|
|
</div>
|
|
<div class="two_box">
|
|
<div class="two_box_t">01-宝宝辅食(文档)</div>
|
|
<div class="two_box_c">
|
|
<div class="child_div">1岁3个月宝宝辅食.doc</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="one_box">
|
|
<div class="one_box_t">0~6岁宝宝辅食</div>
|
|
<div class="one_box_c">
|
|
<div class="two_box">
|
|
<div class="two_box_t">01-宝宝辅食(文档)</div>
|
|
<div class="two_box_c">
|
|
<div class="child_div">1岁3个月宝宝辅食.doc</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="one_box">
|
|
<div class="one_box_t">0~6岁宝宝辅食</div>
|
|
<div class="one_box_c">
|
|
<div class="two_box">
|
|
<div class="two_box_t">01-宝宝辅食(文档)</div>
|
|
<div class="two_box_c">
|
|
<div class="child_div">1岁3个月宝宝辅食.doc</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="one_box">
|
|
<div class="one_box_t">0~6岁宝宝辅食</div>
|
|
<div class="one_box_c">
|
|
<div class="two_box">
|
|
<div class="two_box_t">01-宝宝辅食(文档)</div>
|
|
<div class="two_box_c">
|
|
<div class="child_div">1岁3个月宝宝辅食.doc</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="child_div">12岁以上青少年长高食谱</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// 获取所有一级和二级容器
|
|
const oneBoxes = document.querySelectorAll('.one_box');
|
|
const twoBoxes = document.querySelectorAll('.two_box');
|
|
|
|
// 初始化所有一级容器高度为0
|
|
function resetAllOneBoxes() {
|
|
oneBoxes.forEach(box => {
|
|
const content = box.querySelector('.one_box_c');
|
|
content.style.height = '0';
|
|
});
|
|
}
|
|
|
|
// 一级菜单点击事件
|
|
oneBoxes.forEach(box => {
|
|
const title = box.querySelector('.one_box_t');
|
|
const content = box.querySelector('.one_box_c');
|
|
|
|
title.addEventListener('click', function(e) {
|
|
e.stopPropagation();
|
|
|
|
// 如果当前内容已经展开,则关闭它
|
|
if (content.style.height !== '0px' && content.style.height !== '') {
|
|
content.style.height = '0';
|
|
} else {
|
|
// 否则关闭所有一级菜单,然后展开当前
|
|
resetAllOneBoxes();
|
|
// 计算内容高度并展开
|
|
const contentHeight = content.scrollHeight;
|
|
content.style.height = contentHeight + 'px';
|
|
}
|
|
});
|
|
});
|
|
|
|
// 二级菜单点击事件 - 修改为不影响其他two_box
|
|
twoBoxes.forEach(box => {
|
|
const title = box.querySelector('.two_box_t');
|
|
const content = box.querySelector('.two_box_c');
|
|
|
|
title.addEventListener('click', function(e) {
|
|
e.stopPropagation();
|
|
|
|
// 切换当前二级内容的展开/关闭状态
|
|
if (content.style.height !== '0px' && content.style.height !== '') {
|
|
content.style.height = '0';
|
|
} else {
|
|
const contentHeight = content.scrollHeight;
|
|
content.style.height = contentHeight + 'px';
|
|
}
|
|
});
|
|
});
|
|
|
|
// 初始化所有内容为关闭状态
|
|
resetAllOneBoxes();
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
// 获取所有 child_div 元素
|
|
const childDivs = document.querySelectorAll('.child_div');
|
|
|
|
// 定义 jump 函数
|
|
function jump() {
|
|
const title = this.textContent.trim(); // 获取当前点击的 div 的文本内容
|
|
const encodedTitle = encodeURIComponent(title); // 编码标题,确保 URL 有效
|
|
|
|
// 创建或使用现有的 downloadLink
|
|
let downloadLink = window.downloadLink;
|
|
if (!downloadLink) {
|
|
downloadLink = document.createElement('a');
|
|
downloadLink.style.display = 'none';
|
|
document.body.appendChild(downloadLink);
|
|
window.downloadLink = downloadLink; // 存储为全局变量以便复用
|
|
}
|
|
|
|
// 设置链接并跳转
|
|
// downloadLink.href = `http://wm.reedaw.com/children_meals_cookbook/${encodedTitle}/${encodedTitle}.html`;
|
|
downloadLink.href = `https://tc.pcxbc.com/children_meals_cookbook/${encodedTitle}/${encodedTitle}.html`;
|
|
downloadLink.click();
|
|
}
|
|
|
|
// 为每个 child_div 添加点击事件
|
|
childDivs.forEach(div => {
|
|
div.addEventListener('click', jump);
|
|
div.style.cursor = 'pointer'; // 添加手型光标,提示可点击
|
|
});
|
|
</script> |