o1-mini-2024-09-12· OpenAI
WildChat-4.8M (AI2)
<p> </p> <style> /* تنظیمات پایه برای body و html / html, body { margin: 0;…
- Usercode
- Assistant
/* متغیر CSS برای ارتفاع نمایشگر */
:root {
--vh: 100%;
}
/* کانتینر iframe - initially not full screen */
.iframe-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh; /* ارتفاع کامل نمایشگر */
overflow: hidden; /* مخفی کردن بخشهای اضافی */
z-index: 1; /* ترتیب نمایش */
}
/* تنظیمات iframe */
.iframe-container iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
display: none; /* ابتدا مخفی است */
}
/* Overlay برای مخفی کردن بخش بالایی و پایینی صفحه - برای حالت تمام صفحه */
.overlay-top, .overlay-bottom {
position: fixed;
left: 0;
width: 100%;
background-color: transparent; /* رنگ پسزمینه شفاف */
z-index: 900; /* زیر iframe-container */
pointer-events: none; /* اجازه دادن به اسکرول از طریق iframe */
display: none; /* ابتدا مخفی است */
}
.overlay-top {
top: 0;
height: 192.75px; /* ارتفاع ۵.۱ سانتیمتر (192.75px) */
}
.overlay-bottom {
bottom: 0;
height: 38px; /* ارتفاع ۱ سانتیمتر (38px) */
}
/* نوار پیشرفت و لودینگ */
.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;
}
/* استایل پنجره سفارشی (modal) */
.modal {
display: none;
position: fixed;
z-index: 10002;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 500px;
text-align: center;
border-radius: 5px;
}
.modal-button {
margin-top: 20px;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
}
.cancel-btn {
background-color: #f44336;
color: white;
}
@media (max-width: 768px) {
/* تنظیمات واکنشگرا مخصوص زمانی که دکمههای حذف شده نداریم */
}
@keyframes pulse {
0% { transform: translateY(-50%) scale(1); }
50% { transform: translateY(-50%) scale(1.1); }
100% { transform: translateY(-50%) scale(1); }
}
</style>
let progress = 0;
const progressBar = document.getElementById('progressBar');
const retryButton = document.getElementById('retryButton');
const errorMessage = document.getElementById('errorMessage');
const loadingContainer = document.getElementById('loadingContainer');
const iframe = document.getElementById('myIframe');
const iframeContainer = document.getElementById('iframeContainer');
const overlayTop = document.getElementById('overlayTop');
const overlayBottom = document.getElementById('overlayBottom');
let interval;
let iframeLoadedFlag = false;
function startProgress() {
loadingContainer.style.display = 'flex';
progressBar.style.width = '0%';
progress = 0;
interval = setInterval(() => {
if (progress < 90) { // محدود کردن پیشرفت تا 90%
progress += Math.floor(Math.random() * 10) + 5; // افزایش تصادفی
if (progress > 90) progress = 90;
progressBar.style.width = progress + '%';
}
}, 1000);
}
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(interval);
progressBar.style.width = '100%';
setTimeout(() => {
loadingContainer.style.display = 'none';
iframe.style.display = 'block';
// تنظیم iframe-container به حالت تمام صفحه
iframeContainer.style.height = '100vh';
// نمایش Overlayها برای مخفی کردن بخشهای اضافی
overlayTop.style.display = 'block';
overlayBottom.style.display = 'block';
}, 500); // تاخیر کوچک برای نمایش نوار پیشرفت به 100%
}
function iframeError() {
clearInterval(interval);
loadingContainer.style.display = 'flex';
retryButton.style.display = 'block';
errorMessage.style.display = 'block';
}
function loadIframe() {
fetch(siteURL, { method: 'HEAD', mode: 'no-cors' })
.then(() => {
iframe.src = siteURL;
iframe.onload = iframeLoaded;
iframe.onerror = iframeError;
})
.catch(() => {
iframeError();
});
}
retryButton.addEventListener('click', function() {
progress = 0;
progressBar.style.width = '0%';
iframeLoadedFlag = false;
retryButton.style.display = 'none';
errorMessage.style.display = 'none';
loadingContainer.style.display = 'flex';
iframe.style.display = 'none';
loadIframe();
startProgress();
});
// مدیریت پنجرههای مدال
const imageModal = document.getElementById('myModal');
const closeBtn = document.getElementById('closeBtn');
closeBtn.addEventListener('click', function() {
imageModal.style.display = 'none';
});
window.addEventListener('click', function(event) {
if (event.target == imageModal) {
imageModal.style.display = 'none';
}
});
// تنظیم متغیر CSS برای تنظیم ارتفاع نمایشگر
function setVh() {
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
// فراخوانی تابع برای تنظیم متغیر vh
setVh();
// بهروزرسانی متغیر vh در تغییر اندازه صفحه
window.addEventListener('resize', setVh);
// اجرای بارگذاری iframe و آغاز لودینگ
loadIframe();
startProgress();
</script>
Certainly! Below is the complete, corrected HTML, CSS, and JavaScript code that ensures when the iframe is loaded, the loading screen (including the progress bar and "لطفاً صبر کنید..." message) is fully hidden, and no shadows or overlays interfere with the iframe's display.
iframe and its container have appropriate z-index values to prevent any overlapping shadows from other elements.Here is the complete, unified code:
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<title>صفحه با iframe و نوار پیشرفت</title>
<style>
/* تنظیمات پایه برای body و html */
html, body {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden; /* مخفی کردن اسکرولهای اضافی */
background-color: #f0f0f0; /* رنگ پسزمینه */
font-family: Arial, sans-serif;
}
/* متغیر CSS برای ارتفاع نمایشگر */
:root {
--vh: 100%;
}
/* کانتینر iframe - initially not full screen */
.iframe-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh; /* ارتفاع کامل نمایشگر */
overflow: hidden; /* مخفی کردن بخشهای اضافی */
z-index: 1; /* ترتیب نمایش */
}
/* تنظیمات iframe */
.iframe-container iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
display: none; /* ابتدا مخفی است */
}
/* Overlay برای مخفی کردن بخش بالایی و پایینی صفحه - برای حالت تمام صفحه */
.overlay-top, .overlay-bottom {
position: fixed;
left: 0;
width: 100%;
background-color: transparent; /* رنگ پسزمینه شفاف */
z-index: 900; /* زیر iframe-container */
pointer-events: none; /* اجازه دادن به اسکرول از طریق iframe */
display: none; /* ابتدا مخفی است */
}
.overlay-top {
top: 0;
height: 192.75px; /* ارتفاع ۵.۱ سانتیمتر (192.75px) */
}
.overlay-bottom {
bottom: 0;
height: 38px; /* ارتفاع ۱ سانتیمتر (38px) */
}
/* نوار پیشرفت و لودینگ */
.loading {
position: fixed; /* تغییر به fixed برای پوشش کامل صفحه */
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(240, 240, 240, 0.95); /* پسزمینه کمی شفاف */
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 10000;
}
.loading-message {
margin-bottom: 20px;
font-size: 18px;
color: #333;
}
.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;
}
/* استایل پنجره سفارشی (modal) */
.modal {
display: none;
position: fixed;
z-index: 10002;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 500px;
text-align: center;
border-radius: 5px;
}
.modal-button {
margin-top: 20px;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
}
.cancel-btn {
background-color: #f44336;
color: white;
}
@media (max-width: 768px) {
/* تنظیمات واکنشگرا */
.modal-content {
width: 90%;
}
.loading-message, .error-message {
font-size: 16px;
}
.progress {
width: 90%;
}
}
@keyframes pulse {
0% { transform: translateY(-50%) scale(1); }
50% { transform: translateY(-50%) scale(1.1); }
100% { transform: translateY(-50%) scale(1); }
}
</style>
</head>
<body>
<!-- پنجره سفارشی (modal) برای تصاویر شناسایی شده -->
<div id="myModal" class="modal">
<div class="modal-content">
<p style="text-align: center;">تصاویر شناسایی‌شده</p>
<div class="image-container" id="imageContainer"><!-- تصاویر شناساییشده در اینجا قرار میگیرند --></div>
<button class="modal-button cancel-btn" id="closeBtn">بستن</button>
</div>
</div>
<!-- لودینگ و iframe -->
<div class="iframe-container" id="iframeContainer">
<div class="loading" id="loadingContainer">
<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"></iframe>
</div>
<!-- Overlay برای مخفی کردن بخش بالایی و پایینی صفحه پس از بارگذاری -->
<div class="overlay-top" id="overlayTop"></div>
<div class="overlay-bottom" id="overlayBottom"></div>
<script>
const siteURL = 'https://ovi054-image-to-prompt.hf.space/';
const excludeUrls = [
'https://yanze-pulid.hf.space/--replicas/3t64n/file=/tmp/gradio/7567beceda2541f726af7beb4c9aa857b4a96b77/liuyifei.png'
];
let progress = 0;
const progressBar = document.getElementById('progressBar');
const retryButton = document.getElementById('retryButton');
const errorMessage = document.getElementById('errorMessage');
const loadingContainer = document.getElementById('loadingContainer');
const iframe = document.getElementById('myIframe');
const iframeContainer = document.getElementById('iframeContainer');
const overlayTop = document.getElementById('overlayTop');
const overlayBottom = document.getElementById('overlayBottom');
let interval;
let iframeLoadedFlag = false;
function startProgress() {
loadingContainer.style.display = 'flex';
progressBar.style.width = '0%';
progress = 0;
interval = setInterval(() => {
if (progress < 90) { // محدود کردن پیشرفت تا 90%
progress += Math.floor(Math.random() * 10) + 5; // افزایش تصادفی
if (progress > 90) progress = 90;
progressBar.style.width = progress + '%';
}
}, 1000);
}
function iframeLoaded() {
iframeLoadedFlag = true;
clearInterval(interval);
progressBar.style.width = '100%';
setTimeout(() => {
// پنهان کردن کانتینر لودینگ
loadingContainer.style.display = 'none';
// نمایش iframe
iframe.style.display = 'block';
// نمایش Overlayها برای مخفی کردن بخشهای اضافی
overlayTop.style.display = 'block';
overlayBottom.style.display = 'block';
}, 500); // تاخیر کوچک برای نمایش نوار پیشرفت به 100%
}
function iframeError() {
clearInterval(interval);
errorMessage.style.display = 'block';
retryButton.style.display = 'block';
}
function loadIframe() {
// بررسی پیش از بارگذاری iframe
fetch(siteURL, { method: 'HEAD', mode: 'no-cors' })
.then(() => {
iframe.src = siteURL;
iframe.onload = iframeLoaded;
iframe.onerror = iframeError;
})
.catch(() => {
iframeError();
});
}
retryButton.addEventListener('click', function() {
progress = 0;
progressBar.style.width = '0%';
iframeLoadedFlag = false;
retryButton.style.display = 'none';
errorMessage.style.display = 'none';
loadingContainer.style.display = 'flex';
iframe.style.display = 'none';
overlayTop.style.display = 'none';
overlayBottom.style.display = 'none';
loadIframe();
startProgress();
});
// مدیریت پنجرههای مدال
const imageModal = document.getElementById('myModal');
const closeBtn = document.getElementById('closeBtn');
closeBtn.addEventListener('click', function() {
imageModal.style.display = 'none';
});
window.addEventListener('click', function(event) {
if (event.target == imageModal) {
imageModal.style.display = 'none';
}
});
// تنظیم متغیر CSS برای تنظیم ارتفاع نمایشگر
function setVh() {
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
// فراخوانی تابع برای تنظیم متغیر vh
setVh();
// بهروزرسانی متغیر vh در تغییر اندازه صفحه
window.addEventListener('resize', setVh);
// اجرای بارگذاری iframe و آغاز لودینگ
loadIframe();
startProgress();
</script>
</body>
</html>
پوشش کامل صفحه برای لودینگ:
.loading به fixed و تنظیم ابعاد آن به 100% عرض و ارتفاع نمای صفحه، اطمینان حاصل میکند که صفحه لودینگ کاملاً صفحه را پوشش میدهد و هیچ بخشی از صفحه اصلی قابل مشاهده نیست تا زمانی که لودینگ کامل شود.پنهانسازی کامل لودینگ بعد از بارگذاری:
iframeLoaded، پس از تکمیل بارگذاری، کانتینر لودینگ کامل پنهان میشود و iframe به وضوح نمایش داده میشود.overlayTop و overlayBottom نیز به نمایش در میآیند تا بخشهای اضافی را پوشش دهند بدون اینکه سایهای بر روی محتوای صفحه اصلی بیفتد.مدیریت خطا و امکان بارگذاری مجدد:
iframe با خطا مواجه شود، پیام خطا و دکمه بارگذاری مجدد قابل مشاهده میشود تا کاربر بتواند مجدداً تلاش کند.مدیریت پنجره مدال:
ریسپانسیو بودن طراحی:
این کد اطمینان حاصل میکند که پس از بارگذاری موفق iframe، عناصر بارگذاری کاملاً مخفی شده و iframe بدون هر گونه سایه یا پوشش اضافی به طور کامل قابل مشاهده است. همچنین، در صورت بروز خطا، کاربران میتوانند مجدداً تلاش کنند تا iframe بارگذاری شود.
Not yet included in a published release.