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

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

از ویکی معرفت
بدون خلاصۀ ویرایش
بدون خلاصۀ ویرایش
خط ۱۶: خط ۱۶:
});
});


/* counter effect */
fadeElements.forEach(el => observer.observe(el));
fadeElements.forEach(el => observer.observe(el));


function animateValue(obj, start, end, duration) {
const counters = document.querySelectorAll('.value');
  let startTimestamp = null;
const speed = 200;
  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");
counters.forEach( counter => {
animateValue(obj, 0, 100, 2000);
  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, 5);
        }else{
          counter.innerText = value;
        }
   
  }
 
  animate();
});

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

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'  // بدون آفست اضافی
});

/* counter effect */
fadeElements.forEach(el => observer.observe(el));

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, 5);
        }else{
          counter.innerText = value;
        }
     
   }
   
   animate();
});