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

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

از ویکی معرفت
بدون خلاصۀ ویرایش
برچسب: برگردانده‌شده
بدون خلاصۀ ویرایش
برچسب: واگردانی دستی
خط ۱۲: خط ۱۲:
}, {
}, {
   root: null,        // خود ویوپورت
   root: null,        // خود ویوپورت
   threshold: 0.8,    // ۱۰۰٪ قابل‌مشاهده
   threshold: 1.0,    // ۱۰۰٪ قابل‌مشاهده
   rootMargin: '0px'  // بدون آفست اضافی
   rootMargin: '0px'  // بدون آفست اضافی
});
});

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

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));

function animateValue(obj, start, end, duration) {
  let startTimestamp = null;
  const step = (timestamp) => {
    if (!startTimestamp) startTimestamp = timestamp;
    const progress = Math.min((timestamp - startTimestamp) / duration, 1);
    obj.innerHTML = Math.floor(progress * (end - start) + start);
    if (progress < 1) {
      window.requestAnimationFrame(step);
    }
  };
  window.requestAnimationFrame(step);
}

const obj = document.getElementsByClassName("value");
animateValue(obj, 0, 100, 2000);