您的位置:首页 > Web前端 > JavaScript

JS 实现鼠标滚动页面跳转

2017-10-17 11:18 197 查看

JS 实现鼠标滚动页面跳转

(function() {

var scrollFunc = function(e) {

var ee = e || window.event;

var fullheight = document.body.offsetHeight;

if (e.wheelDelta) { //IE/Opera/Chrome -120是下+120是上

let a= e.wheelDelta;

if (a > 0) {

document.body.scrollTop -=(fullheight-940)/6;

console.log(document.body.scrollTop);

}

if(a<0){

document.body.scrollTop += (fullheight-940)/6;

console.log(document.body.scrollTop);

}

} else if (e.detail) { //Firefox -3是上+3是下

let a = e.detail;

if(a>0){

}

if(a<0){

}

}

}

if (document.addEventListener) {

document.addEventListener(‘DOMMouseScroll’, scrollFunc, false);

} //W3C

window.onmousewheel = document.onmousewheel = scrollFunc; //IE/Opera/Chrome

})()

fullheight 为文档的高度,这个需要你们自己根据自己做的来算了。

还有一种就是之前window.location.href=‘#home‘ 这种跳瞄点的方式来。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: