该网站的基础是 iframe,一次仅显示 1 个。我的问题是 iframe 不滚动,这是绝对位置的问题。我尝试将每个 iframe 包装在它自己的绝对 div 中,以及一些溢出样式。如果 iframe 采用相对样式,则滚动功能可以工作,但格式不正确。奇怪的是,第 6 个 iframe 完美滚动 这是完整的文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Your Website</title>
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
transition: background-color 0.3s ease;
position: relative;
}
#container {
display: flex;
width: 100%; /* Adjust the width as needed */
height: 100vh;
}
#left-column,
#right-column {
text-align: center;
}
#left-column {
width: 20%;
background-color: #ddd;
height: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
transition: width 0.3s ease, background-color 0.3s ease;
}
#left-column:hover {
width: 25%;
background-color: rgb(50, 46, 46);
color: #fff;
}
#left-column nav {
flex-grow: 1;
display: flex;
flex-direction: column;
justify-content: space-evenly;
}
#left-column ul {
list-style: none;
padding: 0;
margin: 0;
}
#left-column li {
height: fit-content;
font-size: 16px;
margin-top: 30px;
cursor: pointer;
transition: font-size 0.3s ease, color 0.3s ease; /* Adjusted transition properties */
}
#left-column li:hover {
font-size: 18px;
color: rgb(140, 142, 148);
}
#middle-section {
margin-left: 10px;
margin-right: 10px;
width: 60%;
height: 100vh;
background-color: #fff;
position: relative;
transition: width 0.3s ease, background-color 0.3s ease;
}
iframe {
width: 100%;
height: 100vh;
border: none;
opacity: 0;
position: absolute; /* Use absolute positioning for iframes */
transition: opacity 0.3s ease;
overflow: auto;
}
iframe.show {
opacity: 1;
}
/* Additional style to make the iframe container responsive */
#middle-section iframe {
display: block;
}
#right-column {
width: 20%;
background-color: #ddd;
padding: 20px;
box-sizing: border-box;
overflow: hidden;
transition: width 0.3s ease, background-color 0.3s ease;
}
#right-column:hover {
width: 25%;
}
</style>
</head>
<body>
<div id="container">
<div id="left-column">
<!-- Content for the left column -->
<nav>
<ul>
<li onclick="showIframe(1)">Fall Prep Coaches</li>
<li onclick="showIframe(2)">Team Real Speed</li>
<li onclick="showIframe(3)">Real Speed Staff</li>
<li onclick="showIframe(4)">Small Group Training</li>
<li onclick="showIframe(5)">Off-Ice Training</li>
<li onclick="showIframe(6)">Tryouts</li>
</ul>
</nav>
</div>
<div id="middle-section">
<!-- Content for the middle section -->
<iframe
id="iframe1"
class="show"
src="https://nefphlcoaches.eu/"
scrolling="yes"
frameborder="0"
></iframe>
<iframe
id="iframe2"
src="https://nefphlcoaches.eu/RealSpeed2/index2.html"
scrolling="yes"
frameborder="0"
></iframe>
<iframe
id="iframe3"
src="https://nefphlcoaches.eu/RealSpeed/index.html"
scrolling="yes"
frameborder="0"
></iframe>
<iframe
id="iframe4"
src="https://nefphlcoaches.eu/SGT/index.html"
scrolling="yes"
frameborder="0"
></iframe>
<iframe
id="iframe5"
src="https://nefphlcoaches.eu/Training/index.html"
scrolling="yes"
frameborder="0"
></iframe>
<iframe
id="iframe6"
src="https://nefphlcoaches.eu/tryout/index.html"
scrolling="yes"
frameborder="0"
></iframe>
</div>
<div id="right-column">
<!-- Content for the right column -->
<h2>Right Column</h2>
<p>Your content goes here.</p>
</div>
</div>
<script>
function showIframe(index) {
document.querySelectorAll("iframe").forEach((iframe) => {
iframe.classList.remove("show");
});
document.getElementById(`iframe${index}`).classList.add("show");
}
</script>
</body>
</html>
<div id="middle-section">
<!-- Content for the middle section -->
<iframe id="iframe6" src="https://nefphlcoaches.eu/tryout/index.html" scrolling="no" frameborder="0"></iframe>
<iframe id="iframe5" src="https://nefphlcoaches.eu/Training/index.html" scrolling="no" frameborder="0"></iframe>
<iframe id="iframe4" src="https://nefphlcoaches.eu/SGT/index.html" scrolling="no" frameborder="0"></iframe>
<iframe id="iframe3" src="https://nefphlcoaches.eu/RealSpeed/index.html" scrolling="no" frameborder="0"></iframe>
<iframe id="iframe2" src="https://nefphlcoaches.eu/RealSpeed2/index2.html" scrolling="no" frameborder="0"></iframe>
<iframe id="iframe1" class="show" src="https://nefphlcoaches.eu/" scrolling="yes" frameborder="0"></iframe>
</div>
注意上面的代码将允许在 iframe1 上滚动
一般来说,通过显示属性切换 iframe 的可见性。
查看 Coach 时不应显示任何其他 iframe (2-6)。