gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
<p> </p> <style> /* تنظیمات پایه برای body و html / html, body { margin: 0;…
- User
/* متغیر CSS برای ارتفاع نمایشگر */ :root { --vh: 100%; } /* کانتینر iframe */ .iframe-container { position: fixed; top: 0; left: 0; width: 100%; height: calc(var(--vh) * 100); /* استفاده از متغیر --vh */ overflow: hidden; /* مخفی کردن بخشهای اضافی */ z-index: 1; /* ترتیب نمایش */ } /* تنظیمات iframe */ .iframe-container iframe { position: absolute; top: -192.75px; /* پنهان کردن ۵.۱ سانتیمتر بالای صفحه (192.75px) */ left: 0; width: 100%; height: calc((var(--vh) * 100) + 192.75px + 38px); /* افزایش ارتفاع iframe به اندازه ۵.۱ سانتیمتر بالا و ۱ سانتیمتر پایین */ border: none; display: none; /* مخفی کردن iframe تا بارگذاری موفق */ } /* Overlay برای مخفی کردن بخش بالایی صفحه */ .overlay-top { position: fixed; top: 0; left: 0; width: 100%; height: 192.75px; /* ارتفاع ۵.۱ سانتیمتر (192.75px) */ background-color: transparent; z-index: 900; pointer-events: none; } /* Overlay برای مخفی کردن بخش پایینی صفحه */ .overlay-bottom { position: fixed; bottom: 0; left: 0; width: 100%; height: 38px; /* ارتفاع ۱ سانتیمتر (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-sizing: border-box; z-index: 2000; display: flex; flex-direction: column; align-items: center; max-width: 90%; } /* Media Query برای موبایل */ @media screen and (max-width: 768px) { .loading { width: 80%; } } .loading-message { margin-bottom: 10px; font-size: 18px; text-align: center; } .error-message { display: none; color: red; text-align: center; margin-top: 10px; font-size: 16px; }// تابع تنظیم متغیر CSS --vh به ارتفاع نمایشگر function setVh() { let vh = window.innerHeight * 0.01; document.documentElement.style.setProperty('--vh', `${vh}px`); } // فراخوانی تابع برای تنظیم متغیر vh setVh(); // بهروزرسانی متغیر vh در تغییر اندازه صفحه window.addEventListener('resize', setVh); // عناصر DOM const loading = document.getElementById('loading'); const errorMessage = document.getElementById('errorMessage'); const iframe = document.getElementById('myIframe'); const overlayTop = document.getElementById('overlayTop'); const overlayBottom = document.getElementById('overlayBottom'); let scrollPosition = 0; const scrollStep = 100; // میزان اسکرول با هر کلیک // پس از ۵ ثانیه، اگر iframe بارگذاری نشده باشد، پیام خطا نمایش داده میشود const errorTimeout = setTimeout(() => { if (!iframeLoaded) { errorMessage.style.display = 'block'; } }, 5000); // هنگام بارگذاری iframe function iframeLoadHandler() { if (!iframeLoaded) { iframeLoaded = true; clearTimeout(errorTimeout); loading.style.display = 'none'; iframe.style.display = 'block'; } } // افزودن رویداد بارگذاری به iframe iframe.addEventListener('load', iframeLoadHandler); // اسکرول کردن iframe با کلیک بر روی Overlay بالایی 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); }); // اسکرول کردن iframe با کلیک بر روی Overlay پایینی 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 با استفاده از چرخش موس در Overlay بالایی overlayTop.addEventListener('wheel', function(e) { e.preventDefault(); const direction = e.deltaY > 0 ? 1 : -1; scrollPosition += direction * scrollStep; scrollPosition = Math.max(0, scrollPosition); iframe.contentWindow.scrollTo(0, scrollPosition); }); // اسکرول کردن iframe با استفاده از چرخش موس در Overlay پایینی overlayBottom.addEventListener('wheel', function(e) { e.preventDefault(); const direction = e.deltaY > 0 ? 1 : -1; scrollPosition += direction * scrollStep; scrollPosition = Math.max(0, scrollPosition); iframe.contentWindow.scrollTo(0, scrollPosition); }); // اسکرول با لمس در Overlay بالایی let touchStartYTop; overlayTop.addEventListener('touchstart', function(e) { touchStartYTop = e.touches[0].clientY; }); overlayTop.addEventListener('touchmove', function(e) { e.preventDefault(); const touchY = e.touches[0].clientY; const direction = touchStartYTop > touchY ? 1 : -1; scrollPosition += direction * scrollStep; scrollPosition = Math.max(0, scrollPosition); iframe.contentWindow.scrollTo(0, scrollPosition); touchStartYTop = touchY; }); // اسکرول با لمس در Overlay پایینی let touchStartYBottom; overlayBottom.addEventListener('touchstart', function(e) { touchStartYBottom = e.touches[0].clientY; }); overlayBottom.addEventListener('touchmove', function(e) { e.preventDefault(); const touchY = e.touches[0].clientY; const direction = touchStartYBottom > touchY ? 1 : -1; scrollPosition += direction * scrollStep; scrollPosition = Math.max(0, scrollPosition); iframe.contentWindow.scrollTo(0, scrollPosition); touchStartYBottom = touchY; }); - Assistant
این کد HTML، CSS و JavaScript برای طراحی یک صفحه وب است که شامل یک عنصر
<iframe>میشود. هدف از این کد، بارگذاری محتوای دیگری درون یک iframe و ارائه تجربهی کاربری خاصی است. در اینجا به توضیح هر بخش میپردازیم:-
HTML:
- یک
<div>با کلاسloadingقرار داده شده که پیامی برای انتظار هنگام بارگذاری محتوا نمایش میدهد. - یک
<iframe>درونiframe-containerقرار داده شده که محتوای خارجی (در اینجا، آدرس "https://yuntian-deng-chatgpt4turbo.hf.space") را بارگذاری میکند. - دو عنصر
<div>به نامهایoverlay-topوoverlay-bottomبهعنوان لایههای پوششدهنده طراحی شدهاند.
- یک
-