مدیاویکی:Common.js: تفاوت میان نسخهها
از ویکی معرفت
More languages
More actions
Nazarzadeh (بحث | مشارکتها) بدون خلاصۀ ویرایش |
Nazarzadeh (بحث | مشارکتها) بدون خلاصۀ ویرایش |
||
| خط ۳: | خط ۳: | ||
const observer = new IntersectionObserver((entries) => { | const observer = new IntersectionObserver((entries) => { | ||
entries.forEach(entry => { | entries.forEach(entry => { | ||
// وقتی حداقل | // وقتی حداقل ۶۰٪ المنت داخل ویوپورت است | ||
if (entry.isIntersecting && entry.intersectionRatio >= 0. | if (entry.isIntersecting && entry.intersectionRatio >= 0.6) { | ||
entry.target.classList.remove('fadein'); | entry.target.classList.remove('fadein'); | ||
entry.target.classList.add('fadedin'); | entry.target.classList.add('fadedin'); | ||
| خط ۱۲: | خط ۱۲: | ||
}, { | }, { | ||
root: null, // ویوپورت | root: null, // ویوپورت | ||
threshold: 0. | threshold: 0.6, // ۶۰٪ | ||
rootMargin: '0px' // بدون حاشیه | rootMargin: '0px' // بدون حاشیه | ||
}); | }); | ||
نسخهٔ ۳۰ نوامبر ۲۰۲۵، ساعت ۰۹:۳۴
const fadeElements = document.querySelectorAll('.fadein');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
// وقتی حداقل ۶۰٪ المنت داخل ویوپورت است
if (entry.isIntersecting && entry.intersectionRatio >= 0.6) {
entry.target.classList.remove('fadein');
entry.target.classList.add('fadedin');
observer.unobserve(entry.target); // فقط یک بار
}
});
}, {
root: null, // ویوپورت
threshold: 0.6, // ۶۰٪
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();
});