به نظر میرسد که مشکل اصلی عدم نمایش نوار پیشرفت به دلیل عدم تعیین ارتفاع صریح برای عنصر #progress است. با تعیین ارتفاع برای این عنصر، نوار پیشرفت به درستی نمایش داده خواهد شد. در ادامه، کد اصلاحشده را با توضیحات لازم ارائه میدهم:
تغییرات اصلی:
-
اضافه کردن ارتفاع به #progress:
با تعیین ارتفاع ثابت (مثلاً 30px) برای عنصر #progress، اطمینان حاصل میکنیم که نوار پیشرفت به درستی نمایش داده میشود.
-
تطبیق بهتر استایلها:
برای اطمینان از نمایش صحیح عناصر دیگر، برخی تنظیمات CSS اضافه شده است.
کد کامل اصلاحشده:
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<title>وبسایت سریع</title>
<style>
/* مخفی کردن تمامی لینکها */
a {
display: none !important;
}
body, html {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden; /* جلوگیری از اسکرول در زمان نمایش نوار پیشرفت */
background-color: #f4f4f9;
font-family: Arial, sans-serif;
}
#loader {
width: 100%;
text-align: center;
position: absolute;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
z-index: 1;
background-color: #f4f4f9;
}
#progress {
width: 80%;
height: 30px; /* اضافه کردن ارتفاع به نوار پیشرفت */
background-color: #eee;
border-radius: 5px;
overflow: hidden;
margin-bottom: 10px;
}
#bar {
width: 0;
height: 100%; /* تنظیم ارتفاع به 100% برای پر شدن کامل #progress */
background-color: #76c7c0;
text-align: center;
line-height: 30px;
color: white;
transition: width 0.15s ease-in-out;
}
.container {
display: none; /* ابتدا مخفی است تا وقتی برنامه Gradio آماده شود */
position: relative;
overflow: hidden;
height: 100vh;
width: 100%;
}
gradio-app {
position: absolute;
top: 0;
left: 0;
right: 0;
width: 100%;
height: 100%;
}
/* استایل دکمه دانلود تصویر */
#downloadButton {
display: none; /* مخفی اولیه */
position: absolute;
top: 20px;
right: 20px;
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
z-index: 2;
}
#downloadButton:hover {
background-color: #45a049;
}
/* استایل مودال اعلان */
.modal {
display: none; /* مخفی است */
position: fixed;
z-index: 3;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.4); /* پسزمینه نیمهشفاف */
}
.modal-content {
background-color: #fefefe;
margin: 10% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 600px;
border-radius: 10px;
position: relative;
text-align: center; /* مرکز کردن محتوا */
}
.close {
color: #aaa;
position: absolute;
top: 10px;
right: 20px;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
}
#modalImageList img {
max-width: 100%;
height: auto;
margin-bottom: 10px;
}
#downloadImages {
background-color: #008CBA;
color: white;
border: none;
padding: 10px 15px;
cursor: pointer;
border-radius: 5px;
margin-top: 20px; /* فاصله بیشتر از دکمه */
}
#downloadImages:hover {
background-color: #007B9E;
}
#instructions {
margin-top: 15px;
font-size: 14px;
color: #555;
}
/* استایل مودال تمام صفحه */
#fullScreenModal {
display: none; /* مخفی است */
position: fixed;
z-index: 4;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.9); /* پسزمینه تاریک */
overflow: auto;
}
.full-screen-content {
position: relative;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
padding: 20px;
box-sizing: border-box;
}
.full-screen-content img {
max-width: 90%;
max-height: 90%;
margin: 10px;
border: 2px solid #fff;
border-radius: 5px;
}
.close-fullscreen {
position: absolute;
top: 20px;
right: 30px;
color: #fff;
font-size: 40px;
font-weight: bold;
cursor: pointer;
}
.close-fullscreen:hover,
.close-fullscreen:focus {
color: #bbb;
text-decoration: none;
}
</style>
</head>
<body>
<!-- دکمه دانلود تصویر -->
<button id="downloadButton">دانلود تصویر</button>
<div id="loader">
<div id="progress">
<div id="bar">0%</div>
</div>
<div>لطفاً صبر کنید...</div>
</div>
<!-- بازیابی تصاویر داخل صفحه از طریق مدل Gradio امکانپذیر نیست، بنابراین این بخش تنها برای نمایش نمونه است -->
<div class="container">
<gradio-app src="https://stabilityai-stable-diffusion-3-5-large.hf.space"></gradio-app>
</div>
<!-- مودال اعلان -->
<div id="imageModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<h2>لیست تصاویر موجود</h2>
<div id="modalImageList"><!-- تصاویر شناسایی شده نمایش داده میشوند --></div>
<button id="downloadImages">نمایش تصاویر</button>
<div id="instructions">برای ذخیره تصاویر، آنها را در حالت تمام صفحه نمایش دهید و از صفحه عکس بگیرید.</div>
</div>
</div>
<!-- مودال تمام صفحه برای نمایش تصاویر -->
<div id="fullScreenModal" class="modal">
<div class="full-screen-content">
<span class="close-fullscreen">×</span>
<div id="fullScreenImageList"><!-- تصاویر کامل صفحه نمایش داده میشوند --></div>
</div>
</div>
<!-- بارگذاری اسکریپت Gradio با async برای بهبود سرعت بارگذاری -->
<script async type="module" src="https://gradio.s3-us-west-2.amazonaws.com/5.3.0/gradio.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
function showContent() {
document.getElementById('loader').style.display = 'none';
document.querySelector('.container').style.display = 'block';
document.body.style.overflow = 'auto'; // بازکردن اسکرول بعد از بارگذاری
document.getElementById('downloadButton').style.display = 'block'; // نمایش دکمه دانلود پس از بارگذاری
}
function simulateProgress(callback) {
let progressElement = document.getElementById('bar');
let progress = 0;
function updateProgress() {
progress += 1;
if (progress > 100) progress = 100;
progressElement.style.width = progress + '%';
progressElement.textContent = progress + '%';
if (progress < 100) {
setTimeout(updateProgress, 150); // بروزرسانی هر 150 میلیثانیه
} else {
callback();
}
}
updateProgress();
}
window.onload = function() {
simulateProgress(showContent);
const gradioApp = document.querySelector('gradio-app');
function checkIfLoaded() {
if (gradioApp && gradioApp.shadowRoot && gradioApp.shadowRoot.querySelector('some-element-inside-gradio')) { // تغییر با عنصر مناسب
document.getElementById('bar').style.width = '100%';
document.getElementById('bar').textContent = '100%';
showContent();
} else {
setTimeout(checkIfLoaded, 100); // بررسی هر 100 میلیثانیه
}
}
checkIfLoaded();
}
// عملکرد دکمه دانلود تصویر
var downloadButton = document.getElementById('downloadButton');
if (downloadButton) {
downloadButton.addEventListener('click', function() {
// شناسایی تصاویر داخل .container و خارج از مودال
const images = document.querySelectorAll('.container img');
if (images.length === 0) {
alert('هیچ تصویری در صفحه یافت نشد.');
return;
}
// نمایش مودال
const modal = document.getElementById('imageModal');
const modalImageList = document.getElementById('modalImageList');
modalImageList.innerHTML = ''; // پاکسازی قبل از اضافه کردن تصاویر جدید
images.forEach((img, index) => {
const imgWrapper = document.createElement('div');
imgWrapper.style.marginBottom = '10px';
const image = document.createElement('img');
image.src = img.src;
image.alt = `تصویر ${index + 1}`; // استفاده از Template Literal صحیح
image.style.maxWidth = '100%';
image.style.height = 'auto';
imgWrapper.appendChild(image);
modalImageList.appendChild(imgWrapper);
});
modal.style.display = 'block';
});
}
// بسته شدن مودال اعلان
var closeModal = document.querySelector('.close');
if (closeModal) {
closeModal.addEventListener('click', function() {
document.getElementById('imageModal').style.display = 'none';
});
}
// کلیک بیرون از مودال برای بستن آن
window.addEventListener('click', function(event) {
const modal = document.getElementById('imageModal');
if (event.target == modal) {
modal.style.display = 'none';
}
});
// عملکرد دکمه نمایش تصاویر در مودال
var downloadImagesButton = document.getElementById('downloadImages');
if (downloadImagesButton) {
downloadImagesButton.addEventListener('click', function() {
const images = document.querySelectorAll('#modalImageList img');
if (images.length === 0) {
alert('هیچ تصویری برای نمایش موجود نیست.');
return;
}
// نمایش مودال تمام صفحه
const fullScreenModal = document.getElementById('fullScreenModal');
const fullScreenImageList = document.getElementById('fullScreenImageList');
fullScreenImageList.innerHTML = ''; // پاکسازی قبل از اضافه کردن تصاویر جدید
images.forEach((img, index) => {
const image = document.createElement('img');
image.src = img.src;
image.alt = `تصویر ${index + 1}`;
fullScreenImageList.appendChild(image);
});
fullScreenModal.style.display = 'block';
// بستن مودال اعلان
document.getElementById('imageModal').style.display = 'none';
});
}
// بسته شدن مودال تمام صفحه
var closeFullScreenModal = document.querySelector('.close-fullscreen');
if (closeFullScreenModal) {
closeFullScreenModal.addEventListener('click', function() {
document.getElementById('fullScreenModal').style.display = 'none';
});
}
// کلیک بیرون از مودال تمام صفحه برای بستن آن
window.addEventListener('click', function(event) {
const fullScreenModal = document.getElementById('fullScreenModal');
if (event.target == fullScreenModal) {
fullScreenModal.style.display = 'none';
}
});
});
</script>
</body>
</html>
توضیحات اضافی:
-
ارتفاع ثابت برای #progress:
#progress {
width: 80%;
height: 30px; /* اضافه کردن ارتفاع */
background-color: #eee;
border-radius: 5px;
overflow: hidden;
margin-bottom: 10px;
}
با تعیین ارتفاع برای #progress، نوار پیشرفت به درستی نمایش داده میشود و فضای مناسب برای نمایش آن فراهم میشود.
-
تنظیم ارتفاع #bar به 100%:
#bar {
width: 0;
height: 100%; /* تنظیم ارتفاع به 100% */
background-color: #76c7c0;
text-align: center;
line-height: 30px;
color: white;
transition: width 0.15s ease-in-out;
}
این کار اطمینان میدهد که نوار پیشرفت تمام ارتفاع #progress را پر کند.
-
تغییرات دیگر:
بررسی کنید که هیچ استایل دیگری نوار پیشرفت را پنهان نکند و یا با دیگر عناصر تداخل نداشته باشد.
نتیجهگیری:
با اعمال این تغییرات، نوار پیشرفت باید به درستی بالای متن "لطفاً صبر کنید" نمایش داده شود و به مرور با افزایش درصد، پر شود. در صورت مواجهه با مشکلات بیشتر، مطمئن شوید که هیچ خطای دیگری در CSS یا JavaScript وجود نداشته باشد که مانع نمایش نوار پیشرفت شود.