|
|
Строка 1: |
Строка 1: |
| const animItems = document.querySelectorAll('._anim_items'); | | const myText = document.getElementById('myText'); |
|
| |
|
| if(animItems.length > 0){
| | myText.addEventListener('mouseover', () => { |
| window.addEventListener('scroll', animOnScroll); | | myText.textContent = 'Да'; |
| function animOnScroll(params) {
| | }); |
| for (let index=0; index < animItems.length; index++) { | |
| const animItem = animItems[index];
| |
| const animItemHeight = animItem.offsetHeight;
| |
| const animItemOffset = offset(animItem).top;
| |
| const animStart = 4;
| |
|
| |
|
| let animItemPoint = window.innerHeight - animItemHeight / animStart;
| | myText.addEventListener('mouseout', () => { |
| | | myText.textContent = 'Агентство национальной безопасности'; |
| if(animItemHeight > window.innerHeight){
| | }); |
| animItemPoint = window.innerHeight - window.innerHeight / animStart;
| |
| }
| |
| if((pageYOffset > animItemOffset - animItemPoint) && pageYOffset < (animItemOffset + animItemHeight)){
| |
| animItem.classList.add('_active');
| |
| } else {
| |
| animItem.classList.remove('_active');
| |
| }
| |
| | |
| }
| |
| }
| |
| function offset(e1) {
| |
| const rect = e1.getBoundingClientRect(), | |
| scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
| |
| scrollTop = window.pageYOffset || document.documentElement.scrollTop;
| |
| return { top: rect.top + scrollTop, left: rect.left + scrollLeft }
| |
| } | |
| animOnScroll();
| |
| }
| |
Версия от 23:16, 2 августа 2024
const myText = document.getElementById('myText');
myText.addEventListener('mouseover', () => {
myText.textContent = 'Да';
});
myText.addEventListener('mouseout', () => {
myText.textContent = 'Агентство национальной безопасности';
});