مطمئناً! در اینجا کدی آماده کردهام که بخش بالای ۶ سانتیمتر و بخش پایین ۱ سانتیمتر یک صفحه وب را مخفی کند. به این ترتیب شما به همان صورت که میخواهید، iframe و overlayها را تنظیم کردهام:
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>صفحه با اسکرول مخفی برای بالا و پایین</title>
<style>
/* تنظیمات پایه برای body و html */
html,
body {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
background-color: #f0f0f0;
}
/* متغیر CSS برای ارتفاع نمایشگر */
:root {
--vh: 100%;
}
/* کانتینر iframe */
.iframe-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: calc(var(--vh) * 100);
overflow: hidden;
z-index: 1;
}
/* تنظیمات iframe */
.iframe-container iframe {
position: absolute;
top: -226.77px;
left: 0;
width: 100%;
height: calc((var(--vh) * 100) + 226.77px + 38px);
border: none;
display: none;
}
/* Overlay برای مخفی کردن بخش بالایی صفحه */
.overlay-top {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 226.77px;
background-color: transparent;
z-index: 900;
pointer-events: none;
}
/* Overlay برای مخفی کردن بخش پایینی صفحه */
.overlay-bottom {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 38px;
background-color: transparent;
z-index: 900;
pointer-events: none;
}
/* لودینگ */
.loading {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
z-index: 2000;
display: flex;
flex-direction: column;
align-items: center;
max-width: 90%;
box-sizing: border-box;
}
/* Media Query برای موبایل */
@media screen and (max-width: 768px) {
.loading {
width: 80%;
}
}
.loading-message {
margin-bottom: 10px;
font-size: 18px;
text-align: center;
}
.progress {
width: 80%;
max-width: 400px;
height: 20px;
background-color: #ddd;
border-radius: 5px;
overflow: hidden;
margin-bottom: 10px;
}
.progress-bar {
height: 100%;
width: 0;
background-color: #4caf50;
transition: width 0.25s;
}
.error-message {
display: none;
color: red;
text-align: center;
margin-bottom: 10px;
font-size: 16px;
}
#retryButton {
display: none;
padding: 10px 20px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
#retryButton:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<!-- لودینگ -->
<div class="loading" id="loading">
<div class="loading-message">لطفاً صبر کنید...</div>
<div class="progress">
<div class="progress-bar" id="progressBar"></div>
</div>
<div class="error-message" id="errorMessage">بارگیری زیاد طول کشید.<br />در صورت عدم بارگذاری، فیلترشکن خود را
روشن کنید.</div>
<button id="retryButton">بارگذاری مجدد</button>
</div>
<!-- کانتینر iframe -->
<div class="iframe-container"><iframe id="myIframe" src="https://yuntian-deng-o1.hf.space" scrolling="yes"></iframe>
</div>
<!-- Overlay برای مخفی کردن بخش بالایی صفحه -->
<div class="overlay-top" id="overlayTop"></div>
<!-- Overlay برای مخفی کردن بخش پایینی صفحه -->
<div class="overlay-bottom" id="overlayBottom"></div>
<script>
let initialLoadCompleted = false;
function setVh() {
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
setVh();
window.addEventListener('resize', setVh);
let progress = 0;
const progressBar = document.getElementById('progressBar');
const retryButton = document.getElementById('retryButton');
const errorMessage = document.getElementById('errorMessage');
const loading = document.getElementById('loading');
const iframe = document.getElementById('myIframe');
const overlayTop = document.getElementById('overlayTop');
const overlayBottom = document.getElementById('overlayBottom');
let progressInterval;
let errorTimeout;
let scrollPosition = 0;
const scrollStep = 100;
function startProgress() {
if (initialLoadCompleted) return;
progressInterval = setInterval(() => {
if (progress < 100) {
progress += 20;
if (progress > 100) progress = 100;
progressBar.style.width = progress + '%';
}
if (progress >= 100) {
clearInterval(progressInterval);
if (!initialLoadCompleted) {
showError();
}
}
}, 1000);
errorTimeout = setTimeout(() => {
if (!initialLoadCompleted) {
showError();
}
}, 5000);
}
function iframeLoaded() {
if (initialLoadCompleted) return;
initialLoadCompleted = true;
clearInterval(progressInterval);
clearTimeout(errorTimeout);
loading.style.display = 'none';
iframe.style.display = 'block';
progressInterval = null;
errorTimeout = null;
}
function iframeError() {
if (initialLoadCompleted) return;
clearInterval(progressInterval);
clearTimeout(errorTimeout);
showError();
}
function showError() {
errorMessage.style.display = 'block';
retryButton.style.display = 'block';
}
function resetLoading() {
progress = 0;
progressBar.style.width = '0%';
initialLoadCompleted = false;
loading.style.display = 'flex';
errorMessage.style.display = 'none';
retryButton.style.display = 'none';
iframe.style.display = 'none';
clearInterval(progressInterval);
clearTimeout(errorTimeout);
iframe.addEventListener('load', iframeLoaded, { once: true });
iframe.addEventListener('error', iframeError, { once: true });
}
function loadIframe() {
iframe.src = iframe.src;
}
retryButton.addEventListener('click', () => {
resetLoading();
loadIframe();
startProgress();
});
overlayTop.addEventListener('click', function (e) {
const clickY = e.clientY;
const overlayHeight = overlayTop.clientHeight;
const direction = clickY > overlayHeight / 2 ? 1 : -1;
scrollPosition += direction * scrollStep;
scrollPosition = Math.max(0, scrollPosition);
iframe.contentWindow.scrollTo(0, scrollPosition);
});
overlayBottom.addEventListener('click', function (e) {
const clickY = e.clientY;
const overlayHeight = overlayBottom.clientHeight;
const direction = clickY > overlayHeight / 2 ? 1 : -1;
scrollPosition += direction * scrollStep;
scrollPosition = Math.max(0, scrollPosition);
iframe.contentWindow.scrollTo(0, scrollPosition);
});
iframe.addEventListener('load', iframeLoaded, { once: true });
iframe.addEventListener('error', iframeError, { once: true });
startProgress();
</script>
</body>
</html>
این کد شامل موارد زیر است:
- iframe از بالای 6 سانتیمتر و از پایین 1 سانتیمتر گسترشیافته تا این قسمتها را پنهان کند.
- بخشهایی برای نمایش پیام لودینگ و پیشرفت، با امکان نمایش پیام خطا در صورت طولانی شدن بارگیری.
- بالا و پایین بخشی از iframe برای اسکرول، روی کلیدهای شفاف تنظیم شده است.