o1-preview-2024-09-12· OpenAI
WildChat-4.8M (AI2)
<!DOCTYPE html> <html lang="fa"> <head> <meta charset="UTF-8"> <!-- تنظیم متا ویوپورت…
- User
iframe { position: absolute; top: 0; left: 0; border: none; /* مخفی کردن iframe تا بارگذاری موفق */ display: none; } .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; text-align: center; } .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; } /* استایل دکمه اسکرول */ .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; } </style><script> let progress = 0; const progressBar = document.getElementById('progressBar'); const retryButton = document.getElementById('retryButton'); const errorMessage = document.getElementById('errorMessage'); let interval; let iframeLoadedFlag = false; 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'; adjustIframeScale(); setupScrollHandle(); // اضافه کردن دکمه اسکرول پس از بارگذاری iframe } 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'); const urlParts = ['https:', '', 'finegrain-finegrain-object-eraser.hf.space', '']; iframe.src = urlParts.join('/'); } function adjustIframeScale() { const iframe = document.getElementById('myIframe'); const container = document.querySelector('.iframe-container'); const desiredWidth = 1024; // عرض سایت اصلی let scale = window.innerWidth / desiredWidth; // جلوگیری از بزرگنمایی بیش از حد در دسکتاپ if (scale > 1) scale = 1; // مقادیر شیفت برای مخفی کردن بخشهایی از بالا و پایین let topShiftAmount = 1; // به سانتیمتر let bottomShiftAmount = 5; // به سانتیمتر (تغییر از 4 به 5) // تبدیل سانتیمتر به پیکسل (تقریبی) let pixelsPerCm = 37.8; // تعداد پیکسل در یک سانتیمتر (استاندارد 96dpi) let topShiftPixels = topShiftAmount * pixelsPerCm; let bottomShiftPixels = bottomShiftAmount * pixelsPerCm; // تطبیق با مقیاس let scaledTopShift = topShiftPixels / scale; let scaledBottomShift = bottomShiftPixels / scale; // تنظیم استایل iframe iframe.style.transform = 'scale(' + scale + ')'; iframe.style.transformOrigin = '0 0'; iframe.style.width = desiredWidth + 'px'; // شیفت iframe به بالا iframe.style.top = -scaledTopShift + 'px'; // محاسبه ارتفاع iframe iframe.style.height = (window.innerHeight / scale) + scaledTopShift - scaledBottomShift + 'px'; // تنظیم اندازه کانتینر container.style.width = window.innerWidth + 'px'; container.style.height = window.innerHeight + 'px'; } // تابع برای تنظیم دکمه اسکرول function setupScrollHandle() { const scrollHandle = document.querySelector('.scroll-handle'); const iframe = document.getElementById('myIframe'); let isDragging = false; let startY, startScrollY; 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; // دسترسی به محتوای iframe برای اسکرول try { startScrollY = iframe.contentWindow.pageYOffset; } catch (error) { console.error('Cannot access iframe content:', error); isDragging = false; } 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; try { iframe.contentWindow.scrollTo(0, startScrollY - walk); } catch (error) { console.error('Cannot scroll iframe:', error); isDragging = false; } } function stopDragging() { isDragging = false; scrollHandle.style.cursor = 'grab'; } } window.addEventListener('resize', adjustIframeScale); loadIframe(); startProgress(); </script> - Assistant
برای مخفی کردن 6 سانتیمتر از پایین به جای 5 سانتیمتر، کافیست مقدار متغیر
bottomShiftAmountرا در تابعadjustIframeScaleاز 5 به 6 تغییر دهید. به صورت زیر:// مقدار قبلی: let bottomShiftAmount = 5; // به سانتیمتر (تغییر از 4 به 5) // مقدار جدید: let bottomShiftAmount = 6; // به سانتیمتردر نتیجه، کد کامل شما پس از اعمال تغییر به صورت زیر خواهد بود:
<!DOCTYPE html> <html lang="fa"> <head> <meta charset="UTF-8"> <!-- تنظیم متا ویوپورت برای هماهنگی با اندازه دستگاه --> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> <style> html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; /* جلوگیری از اسکرول در صفحه اصلی */ } .iframe-container { position: relative; overflow: hidden; /* مخفی کردن بخشهای اضافی */ width: 100%; height: 100%; } iframe { position: absolute; top: 0; left: 0; border: none; /* مخفی کردن iframe تا بارگذاری موفق */ display: none; } .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; text-align: center; } .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; } /* استایل دکمه اسکرول */ .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; } </style> </head> <body> <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> <div class="iframe-container"> <iframe id="myIframe" onload="iframeLoaded()" onerror="iframeError()" allowfullscreen="allowfullscreen"></iframe> </div> <!-- دکمه اسکرول --> <div class="scroll-handle" title="برای اسکرول بکشید" role="button" aria-label="دکمه اسکرول">👆</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; 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'; adjustIframeScale(); setupScrollHandle(); // اضافه کردن دکمه اسکرول پس از بارگذاری iframe } 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'); const urlParts = ['https:', '', 'finegrain-finegrain-object-eraser.hf.space', '']; iframe.src = urlParts.join('/'); } function adjustIframeScale() { const iframe = document.getElementById('myIframe'); const container = document.querySelector('.iframe-container'); const desiredWidth = 1024; // عرض سایت اصلی let scale = window.innerWidth / desiredWidth; // جلوگیری از بزرگنمایی بیش از حد در دسکتاپ if (scale > 1) scale = 1; // مقادیر شیفت برای مخفی کردن بخشهایی از بالا و پایین let topShiftAmount = 1; // به سانتیمتر let bottomShiftAmount = 6; // به سانتیمتر // تبدیل سانتیمتر به پیکسل (تقریبی) let pixelsPerCm = 37.8; // تعداد پیکسل در یک سانتیمتر (استاندارد 96dpi) let topShiftPixels = topShiftAmount * pixelsPerCm; let bottomShiftPixels = bottomShiftAmount * pixelsPerCm; // تطبیق با مقیاس let scaledTopShift = topShiftPixels / scale; let scaledBottomShift = bottomShiftPixels / scale; // تنظیم استایل iframe iframe.style.transform = 'scale(' + scale + ')'; iframe.style.transformOrigin = '0 0'; iframe.style.width = desiredWidth + 'px'; // شیفت iframe به بالا iframe.style.top = -scaledTopShift + 'px'; // محاسبه ارتفاع iframe iframe.style.height = (window.innerHeight / scale) + scaledTopShift - scaledBottomShift + 'px'; // تنظیم اندازه کانتینر container.style.width = window.innerWidth + 'px'; container.style.height = window.innerHeight + 'px'; } // تابع برای تنظیم دکمه اسکرول function setupScrollHandle() { const scrollHandle = document.querySelector('.scroll-handle'); const iframe = document.getElementById('myIframe'); let isDragging = false; let startY, startScrollY; 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; // دسترسی به محتوای iframe برای اسکرول try { startScrollY = iframe.contentWindow.pageYOffset; } catch (error) { console.error('Cannot access iframe content:', error); isDragging = false; } 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; try { iframe.contentWindow.scrollTo(0, startScrollY - walk); } catch (error) { console.error('Cannot scroll iframe:', error); isDragging = false; } } function stopDragging() { isDragging = false; scrollHandle.style.cursor = 'grab'; } } window.addEventListener('resize', adjustIframeScale); loadIframe(); startProgress(); </script> </body> </html>با این تغییر، 6 سانتیمتر از پایین iframe مخفی میشود.
اگر نیاز به تغییرات بیشتری دارید یا سوال دیگری برایتان پیش آمد، خوشحال میشوم کمک کنم.