مدیاویکی:Common.js: تفاوت میان نسخهها
از ویکی معرفت
More languages
More actions
Nazarzadeh (بحث | مشارکتها) بدون خلاصۀ ویرایش |
Nazarzadeh (بحث | مشارکتها) بدون خلاصۀ ویرایش |
||
| خط ۱۵: | خط ۱۵: | ||
rootMargin: '0px' // بدون آفست اضافی | rootMargin: '0px' // بدون آفست اضافی | ||
}); | }); | ||
fadeElements.forEach(el => observer.observe(el)); | |||
/* counter effect */ | /* counter effect */ | ||
const counters = document.querySelectorAll('.value'); | const counters = document.querySelectorAll('.value'); | ||
| خط ۳۰: | خط ۳۰: | ||
if(data < value) { | if(data < value) { | ||
counter.innerText = Math.ceil(data + time); | counter.innerText = Math.ceil(data + time); | ||
setTimeout(animate, | setTimeout(animate, 1); | ||
}else{ | }else{ | ||
counter.innerText = value; | counter.innerText = value; | ||
نسخهٔ ۲۹ نوامبر ۲۰۲۵، ساعت ۰۹:۱۶
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));
/* 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();
});