I am trying to trigger an event on scroll at certain height. Specifically yo add a style, and my code works in Chrome, but not in IE. Can anyone assist?
myID = document.getElementById("subnav");
var myScrollFunc2 = function() {
var y = window.scrollY;
if (y >= 150) {
myID.className = "subnav stick";
} else {
myID.className = "subnav unstick";
}
};
window.addEventListener("scroll", myScrollFunc2);
.subnav {
width: 100%;
z-index: 100;
background-color: #ffffff;
}
.stick {
top: -62px;
position: fixed !important;
}
.unstick {
position: relative !important;
}
<div id="subnav">123</div>