PC版电脑微信内置浏览器不支持touch事件的变通解决办法

一H5页面本来在移动端跑的好好的,用的alloyTouch组件,结果老板硬生生要在电脑版微信里打开,PC端没有touch事件,结果滑不动,只好想点兼容变通的办法,上代码:

//    兼容PC版微信滚轮事件代替touch    //
    $(document).on('mousewheel DOMMouseScroll', onMouseScroll);
    function onMouseScroll(e){
        e.preventDefault();
        var wheel = e.originalEvent.wheelDelta || -e.originalEvent.detail;
        var delta = Math.max(-1, Math.min(1, wheel) );
        if(delta<0){                //    向下滚动
            console.log('向下滚动 ');
        }else{                        //    向上滚动
            console.log('向上滚动 ');
        }    
    }

猜你喜欢

转载自www.cnblogs.com/tindy/p/9299946.html