مدیاویکی:Common.js: تفاوت میان نسخهها
از ویکی معرفت
More languages
More actions
Nazarzadeh (بحث | مشارکتها) بدون خلاصۀ ویرایش |
Nazarzadeh (بحث | مشارکتها) بدون خلاصۀ ویرایش |
||
| خط ۱۷: | خط ۱۷: | ||
fadeElements.forEach(el => observer.observe(el)); | 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.getElementByClass("value"); | |||
animateValue(obj, 0, 100, 2000); | |||
نسخهٔ ۲۹ نوامبر ۲۰۲۵، ساعت ۰۸:۳۷
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.getElementByClass("value");
animateValue(obj, 0, 100, 2000);