最新免费网站源码,手机网页自动跳转怎么处理,海外购物平台都有哪些,做网站还能挣钱本文实例为大家分享了js实现鼠标滑动到某个div禁止滚动的具体代码#xff0c;供大家参考#xff0c;具体内容如下项目中碰到一个场景就是当鼠标滑倒某个div的时候#xff0c;滑动鼠标页面不再滚动。这里主要是当鼠标滑动到该div时#xff0c;监听滚轮事件并通过preventDefa…本文实例为大家分享了js实现鼠标滑动到某个div禁止滚动的具体代码供大家参考具体内容如下项目中碰到一个场景就是当鼠标滑倒某个div的时候滑动鼠标页面不再滚动。这里主要是当鼠标滑动到该div时监听滚轮事件并通过preventDefault()事件来阻止滚动事件以下是例子eg:#wrap {position:absolute;top:200px;background:#000000;font-size: 40px;width:50vw;text-align: center;color: #ffffff;line-height: 300px;height:300px;}鼠标移动进入该区域页面禁止滚动window.onload function () {for (i 0; i 50; i) {var x document.createElement(div);x.innerHTML test;document.body.appendChild(x);}function $(x) {return document.getElementById(x);};$(wrap).onmousewheel function scrollWheel(e) {var sl;e e || window.event;if (navigator.userAgent.toLowerCase().indexOf(msie) 0) {event.returnValue false;} else {e.preventDefault();};};if (navigator.userAgent.toLowerCase().indexOf(firefox) 0) {//firefox支持onmousewheeladdEventListener(DOMMouseScroll,function (e) {var obj e.target;var onmousewheel;while (obj) {onmousewheel obj.getAttribute(onmousewheel) || obj.onmousewheel;if (onmousewheel) break;if (obj.tagName BODY) break;obj obj.parentNode;};if (onmousewheel) {if (e.preventDefault) e.preventDefault();e.returnValue false; //禁止页面滚动if (typeof obj.onmousewheel ! function) {//将onmousewheel转换成functioneval(window._tmpFun function(event){ onmousewheel });obj.onmousewheel window._tmpFun;window._tmpFun null;};// 不直接执行是因为若onmousewheel(e)运行时间较长的话会导致锁定滚动失效使用setTimeout可避免setTimeout(function () {obj.onmousewheel(e);},1);};},false);};}以上就是本文的全部内容希望对大家的学习有所帮助也希望大家多多支持脚本之家。