در اینجا کد شما را با اعمال تغییرات مورد نظر آماده کردهام. در این کد، ۳ سانتیمتر از بالای سایت و ۲ سانتیمتر از پایین سایت داخل iframe مخفی شده است.
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>iframe Loader with Scroll Button and Download</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden; /* جلوگیری از اسکرول در صفحه اصلی */
height: 100vh;
background-color: #f0f0f0;
}
.iframe-container {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden; /* مخفی کردن قسمتهای اضافی iframe */
}
iframe {
width: 100%;
height: calc(100% + 189px); /* افزایش ارتفاع برای جبران جابجایی */
border: none;
display: none;
position: relative;
top: -113.4px; /* مخفی کردن ۳ سانتیمتر از بالا */
}
.loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
z-index: 10000;
}
.loading-message {
margin-bottom: 20px;
font-size: 18px;
}
.progress {
width: 80%;
max-width: 400px;
height: 20px;
background-color: #ddd;
border-radius: 5px;
overflow: hidden;
}
.progress-bar {
height: 100%;
width: 0;
background-color: #4caf50;
transition: width 1s;
}
.error-message {
display: none;
color: red;
margin-top: 20px;
font-size: 16px;
text-align: center;
}
#retryButton {
display: none;
margin-top: 10px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
}
/* سایر استایلهای شما */
.scroll-handle {
position: fixed;
right: 15px;
top: 50%;
transform: translateY(-50%);
z-index: 9999;
width: 45px;
height: 45px;
border-radius: 50%;
background-color: rgba(0, 0, 0, 0.4);
color: white;
border: none;
cursor: grab;
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
transition: all 0.3s;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.scroll-handle:active {
cursor: grabbing;
background-color: rgba(0, 0, 0, 0.6);
box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}
@media (max-width: 768px) {
.scroll-handle {
right: 10px;
width: 40px;
height: 40px;
font-size: 22px;
}
}
@keyframes pulse {
0% { transform: translateY(-50%) scale(1); }
50% { transform: translateY(-50%) scale(1.1); }
100% { transform: translateY(-50%) scale(1); }
}
.scroll-handle:hover {
animation: pulse 1s infinite;
}
.input-container {
width: 98%;
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
padding: 10px;
display: flex;
flex-direction: column;
margin: 10px auto;
}
.input-box {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 14px;
resize: none;
}
.input-box::placeholder {
color: #999;
font-size: 14px;
}
.message {
margin-top: 5px;
font-size: 12px;
color: #4CAF50;
}
.download-link {
display: none;
margin-top: 10px;
padding: 8px 12px;
background-color: #4CAF50;
color: white;
text-decoration: none;
border-radius: 4px;
font-size: 14px;
text-align: center;
}
.download-link:hover {
background-color: #45a049;
}
.instructions {
margin-top: 10px;
font-size: 12px;
color: #666;
}
</style>
</head>
<body>
<div class="iframe-container">
<div class="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 id="myIframe" onload="iframeLoaded()" onerror="iframeError()"></iframe>
</div>
<div class="scroll-handle" title="برای اسکرول بکشید" role="button" aria-label="دکمه اسکرول">👆</div>
<div class="input-container">
<input type="text" class="input-box" placeholder="برای دانلود صدا دکمه دانلود را محکم بگیر اینجا بکش" />
<div class="message"></div>
<a href="#" class="download-link" target="_blank">دانلود صدا</a>
<div class="instructions"></div>
</div>
<script>
let progress = 0;
const progressBar = document.getElementById('progressBar');
const retryButton = document.getElementById('retryButton');
const errorMessage = document.getElementById('errorMessage');
let interval;
let iframeLoadedFlag = false;
let isDragging = false;
let startY, startScrollY;
function startProgress() {
interval = setInterval(() => {
if (progress < 100) {
progress += 10;
progressBar.style.width = progress + '%';
}
if (progress === 100) {
clearInterval(interval);
if (!iframeLoadedFlag) {
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
}
}, 1000);
}
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(interval);
document.querySelector('.loading').style.display = 'none';
const iframe = document.getElementById('myIframe');
iframe.style.display = 'block';
setupScrollHandle();
}
function iframeError() {
clearInterval(interval);
document.querySelector('.loading').style.display = 'none';
errorMessage.style.display = 'block';
retryButton.style.display = 'block';
}
retryButton.addEventListener('click', function() {
progress = 0;
progressBar.style.width = '0%';
iframeLoadedFlag = false;
document.querySelector('.loading').style.display = 'flex';
retryButton.style.display = 'none';
errorMessage.style.display = 'none';
const iframe = document.getElementById('myIframe');
iframe.style.display = 'none';
loadIframe();
startProgress();
});
function loadIframe() {
const iframe = document.getElementById('myIframe');
iframe.src = 'https://nick088-edge-tts.hf.space';
}
function setupScrollHandle() {
const scrollHandle = document.querySelector('.scroll-handle');
const iframe = document.getElementById('myIframe');
scrollHandle.addEventListener('mousedown', startDragging);
scrollHandle.addEventListener('touchstart', startDragging);
document.addEventListener('mousemove', drag);
document.addEventListener('touchmove', drag);
document.addEventListener('mouseup', stopDragging);
document.addEventListener('touchend', stopDragging);
function startDragging(e) {
isDragging = true;
startY = e.clientY || e.touches[0].clientY;
startScrollY = iframe.contentWindow.pageYOffset;
scrollHandle.style.cursor = 'grabbing';
}
function drag(e) {
if (!isDragging) return;
e.preventDefault();
const y = e.clientY || e.touches[0].clientY;
const walk = (y - startY) * 2;
iframe.contentWindow.scrollTo(0, startScrollY - walk);
}
function stopDragging() {
isDragging = false;
scrollHandle.style.cursor = 'grab';
}
}
const inputBox = document.querySelector('.input-box');
const message = document.querySelector('.message');
const downloadLink = document.querySelector('.download-link');
const instructions = document.querySelector('.instructions');
function isValidUrl(string) {
try {
new URL(string);
return true;
} catch (_) {
return false;
}
}
function handleInput() {
const link = inputBox.value.trim();
if (isValidUrl(link)) {
message.textContent = 'لینک دانلود را گرفتم';
downloadLink.style.display = 'block';
downloadLink.href = link;
instructions.innerHTML = 'برای دانلود صدا:<br>' +
'1. روی دکمه "دانلود صدا" کلیک کنید.<br>' +
'2. بعد از باز شدن مرورگر، روی "سمت راست صدا کلیک کنید" و "بارگیری صدا" را انتخاب کنید.<br>' +
'3. صدا داخل گوشی ذخیره میشود.';
} else {
message.textContent = '';
downloadLink.style.display = 'none';
instructions.textContent = '';
}
}
inputBox.addEventListener('input', handleInput);
inputBox.addEventListener('paste', handleInput);
inputBox.addEventListener('dragover', function(e) {
e.preventDefault();
});
inputBox.addEventListener('drop', function(e) {
e.preventDefault();
const link = e.dataTransfer.getData('text');
this.value = link;
handleInput();
});
downloadLink.addEventListener('click', function() {
setTimeout(() => {
inputBox.value = '';
message.textContent = '';
downloadLink.style.display = 'none';
instructions.textContent = '';
}, 100);
});
loadIframe();
startProgress();
</script>
</body>
</html>
توضیحات تغییرات:
-
در بخش CSS، به تگ iframe استایل زیر اضافه شده است:
iframe {
width: 100%;
height: calc(100% + 189px); /* افزایش ارتفاع برای جبران جابجایی */
border: none;
display: none;
position: relative;
top: -113.4px; /* مخفی کردن ۳ سانتیمتر از بالا */
}
این تغییرات باعث میشود ۳ سانتیمتر از بالای iframe مخفی شود و ارتفاع iframe برای جبران این جابجایی افزایش یابد.
-
همچنین، با استفاده از overflow: hidden در .iframe-container قسمتهای اضافی از پایین iframe مخفی میشوند، بنابراین ۲ سانتیمتر از پایین نیز مخفی خواهد شد.
-
مقادیر ۳ سانتیمتر و ۲ سانتیمتر بر اساس تبدیل به پیکسل به ترتیب تقریباً برابر با 113.4px و 75.6px هستند (هر سانتیمتر ≈ 37.8px).
با این تغییرات، صفحه داخل iframe بهگونهای نمایش داده میشود که ۳ سانتیمتر از بالا و ۲ سانتیمتر از پایین مخفی شده است.
امیدوارم این کد نیاز شما را برطرف کند. اگر سؤال یا مشکلی داشتید، بفرمایید.