windowAddMouseWheel(); function windowAddMouseWheel() { var scrollFunc = function (e) { e = e || window.event; if (e.wheelDelta) { //Determine browser IE, Google wheel events if (e.wheelDelta > 0) { //When the wheel scrolls down alert("The wheel scrolls up"); } if (e.wheelDelta < 0) { //When the wheel rolls up alert("The wheel scrolls down"); } } else if (e.detail) { //Firefox wheel event if (e.detail> 0) { //When the wheel scrolls down alert("The wheel scrolls up"); } if (e.detail< 0) { //When the wheel scrolls up alert("The wheel scrolls down"); } } }; / / Bind the wheel scroll event to the page if (document.addEventListener) { document.addEventListener('DOMMouseScroll', scrollFunc, false); } //The scroll wheel triggers the scrollFunc method window.onmousewheel = document.onmousewheel = scrollFunc; }
window.onscroll=function(){ //The variable t is the distance to the top when the scroll bar scrolls var t =document.documentElement.scrollTop||document.body.scrollTop; }