Показать сообщение отдельно
  #3 (permalink)  
Старый 01.04.2020, 09:56
Профессор
Отправить личное сообщение для Сергей Ракипов Посмотреть профиль Найти все сообщения от Сергей Ракипов
 
Регистрация: 01.06.2010
Сообщений: 651

Сообщение от рони
addEventListener( "resize", test)
Я так и сделал но функции срабатывают только если были изменение а если просто открыто то не чего.

let navHover = document.querySelector(".nav_hover");
let navListDescop = document.querySelector(".navig:nth-child(10)");
let navListPhone = document.querySelector(".navig:nth-child(2)");
let descop = document.querySelector(".navig:nth-child(10)");
let phone =document.querySelector(".navig:nth-child(2)");

function test(){
    if (document.documentElement.clientWidth < 860) {
        navHover.onmouseover = navOn2;
        navHover.onmouseout = navOff2;
        navListPhone.onmouseover = navListOn2;
        navListPhone.onmouseout = navListOff2;

        function navOn2(){
            phone.style.marginTop = "0px";
        }
        function navOff2(){
            phone.style.marginTop = "-1500px";
        }
        function navListOn2(){
            phone.style.marginTop = "0px";
        }
        function navListOff2(){
            phone.style.marginTop = "-1500px";
        }
    }
}

addEventListener( "resize", test);

function test2(){
	if(document.documentElement.clientWidth > 860){
		navHover.onmouseover = navOn;
		navHover.onmouseout = navOff;
		navListDescop.onmouseover = navListOn;
		navListDescop.onmouseout = navListOff;

		function navOn(){
			descop.style.top = "320px";
		}
		function navOff(){
			descop.style.top = "-360px";
		}
		function navListOn(){
			descop.style.top = "320px";
		}
		function navListOff(){
			descop.style.top = "-360px";
		}
	}
}

addEventListener( "resize", test2);
Ответить с цитированием