jquery 鼠標 滑輪 滾動 方向

var scrollFunc = function (e) {

        var direct = 0;

        e = e || window.event;

        if (e.wheelDelta) {  //判斷瀏覽器IE,谷歌滑輪事件             

            if (e.wheelDelta > 0) { //當滑輪向上滾動時

                alert("滑輪向上滾動");

            }

            if (e.wheelDelta < 0) { //當滑輪向下滾動時

                alert("滑輪向下滾動");

            }

        } else if (e.detail) {  //Firefox滑輪事件

            if (e.detail> 0) { //當滑輪向上滾動時

                alert("滑輪向上滾動");

            }

            if (e.detail< 0) { //當滑輪向下滾動時

                alert("滑輪向下滾動");

            }

        }

    }

    //給頁面綁定滑輪滾動事件

    if (document.addEventListener) {

        document.addEventListener('DOMMouseScroll', scrollFunc, false);

    }

    //滾動滑輪觸發scrollFunc方法

    window.onmousewheel = document.onmousewheel = scrollFunc;  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章