Estoy trabajando en una aplicación pequeña.
quiero mostrar el div si el usuario se desplaza hacia arriba a> 100px desde la posición actual
y ocultar div si el usuario se desplaza hacia abajo a> 50 px desde la posición actual
código de ejemplo
myID = document.getElementById("myID"); var myScrollFunc = function() { var y = window.scrollY; if (y >= 200) { myID.className = "bottomMenu show" } else { myID.className = "bottomMenu hide" } }; window.addEventListener("scroll", myScrollFunc); body { height: 2000px; } .bottomMenu { position: fixed; bottom: 0; width: 100%; height: 60px; border-top: 1px solid #000; background: red; z-index: 1; transition: all 1s; } .hide { opacity: 0; left: -100%; } .show { opacity: 1; left: 0; } <div id="myID" class="bottomMenu hide"></div>¿alguien puede ayudar con el código en javascript?
Encontré la manera de resolver esto
ejemplo de código
myID = document.getElementById("myID"); function showSmartMenu() { // current scroll position var st = window.pageYOffset || document.documentElement.scrollTop; // scrolling up if (st < lastScrollTop) { upCounter += 1; downCounter = 0; if (upCounter == 100) { myID.className = "bottomMenu show" } } else { // scrolling down downCounter -= 1; upCounter = 0; if (downCounter == -50) { myID.className = "bottomMenu hide" } } lastScrollTop = st <= 0 ? 0 : st; } var lastScrollTop = 0; var upCounter = 0 var downCounter = 0 window.addEventListener("scroll", showSmartMenu) body { height: 2000px; } .bottomMenu { position: fixed; bottom: 0; width: 100%; height: 60px; border-top: 1px solid #000; background: red; z-index: 1; transition: all 1s; } .hide { opacity: 0; left: -100%; } .show { opacity: 1; left: 0; } <div id="myID" class="bottomMenu hide"></div>