مدیاویکی:Common.js: تفاوت میان نسخهها
از ویکی معرفت
More languages
More actions
Nazarzadeh (بحث | مشارکتها) بدون خلاصۀ ویرایش برچسب: برگرداندهشده |
Nazarzadeh (بحث | مشارکتها) بدون خلاصۀ ویرایش برچسب: واگردانی دستی |
||
| خط ۱۲: | خط ۱۲: | ||
}, { | }, { | ||
root: null, // خود ویوپورت | root: null, // خود ویوپورت | ||
threshold: 0 | 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);