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

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

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

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

/* counter effect */

const counters = document.querySelectorAll('.value');
const speed = 200;

counters.forEach( counter => {
   const animate = () => {
      const value = +counter.getAttribute('akhi');
      const data = +counter.innerText;
     
      const time = value / speed;
     if(data < value) {
          counter.innerText = Math.ceil(data + time);
          setTimeout(animate, 1);
        }else{
          counter.innerText = value;
        }
     
   }
   
   animate();
});