تغییر منو
Toggle preferences menu
تغییر منوی شخصی
به سامانه وارد نشده‌اید
Your IP address will be publicly visible if you make any edits.

مدیاویکی:Common.js: تفاوت میان نسخه‌ها

از ویکی معرفت
بدون خلاصۀ ویرایش
بدون خلاصۀ ویرایش
خط ۱: خط ۱:
/* fade in effect*/
const fadeElements = document.querySelectorAll('.fadein');
const fadeElements = document.querySelectorAll('.fadein');


const observer = new IntersectionObserver((entries) => {
const observer = new IntersectionObserver((entries) => {
   entries.forEach(entry => {
   entries.forEach(entry => {
     if (entry.isIntersecting) {
    // فقط وقتی کل المنت داخل ویوپورت است
     if (entry.isIntersecting && entry.intersectionRatio === 1) {
       entry.target.classList.remove('fadein');
       entry.target.classList.remove('fadein');
       entry.target.classList.add('fadedin');
       entry.target.classList.add('fadedin');
      observer.unobserve(entry.target); // فقط یک‌بار انیمیشن
     }
     }
   });
   });
}, {
}, {
   threshold: 0.5, // 10% المنت وارد viewport شود
  root: null,        // خود ویوپورت
   // rootMargin: '0px 0px -10% 0px' // کمی قبل از کامل ورود
   threshold: 1.0,   // ۱۰۰٪ قابل‌مشاهده
   rootMargin: '0px' // بدون آفست اضافی
});
});


// مشاهده تمام المنت‌ها
fadeElements.forEach(el => observer.observe(el));
fadeElements.forEach(el => observer.observe(el));

نسخهٔ ‏۲۹ نوامبر ۲۰۲۵، ساعت ۰۸:۲۰

const fadeElements = document.querySelectorAll('.fadein');

const observer = new IntersectionObserver((entries) => {
  entries.forEach(entry => {
    // فقط وقتی کل المنت داخل ویوپورت است
    if (entry.isIntersecting && entry.intersectionRatio === 1) {
      entry.target.classList.remove('fadein');
      entry.target.classList.add('fadedin');
      observer.unobserve(entry.target); // فقط یک‌بار انیمیشن
    }
  });
}, {
  root: null,        // خود ویوپورت
  threshold: 1.0,    // ۱۰۰٪ قابل‌مشاهده
  rootMargin: '0px'  // بدون آفست اضافی
});

fadeElements.forEach(el => observer.observe(el));