1. 代码:
// left: 37, up: 38, right: 39, down: 40, // spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36 var keys = {37: 1, 38: 1, 39: 1, 40: 1}; function preventDefault(e) { e = e || window.event; if (e.preventDefault) e.preventDefault(); e.returnValue = false; } function preventDefaultForScrollKeys(e) { if (keys[e.keyCode]) { preventDefault(e); return false; } } function disableScroll() { if (window.addEventListener) // older FF window.addEventListener('DOMMouseScroll', preventDefault, false); window.onwheel = preventDefault; // modern standard window.onmousewheel = document.onmousewheel = preventDefault; // older browsers, IE window.ontouchmove = preventDefault; // mobile document.onkeydown = preventDefaultForScrollKeys; } function enableScroll() { if (window.removeEventListener) window.removeEventListener('DOMMouseScroll', preventDefault, false); window.onmousewheel = document.onmousewheel = null; window.onwheel = null; window.ontouchmove = null; document.onkeydown = null; }
实例:http://output.jsbin.com/xatidu/4/
转自:http://stackoverflow.com/a/4770179/4484798
2. 以上功能的jquery版:
/** * $.disablescroll * Author: Josh Harrison - aloofdesign.com * * Disables scroll events from mousewheels, touchmoves and keypresses. * Use while jQuery is animating the scroll position for a guaranteed super-smooth ride! */(function(e){"use strict";function r(t,n){this.opts=e.extend({handleKeys:!0,scrollEventKeys:[32,33,34,35,36,37,38,39,40]},n);this.$container=t;this.$document=e(document);this.lockToScrollPos=[0,0];this.disable()}var t,n;n=r.prototype;n.disable=function(){var e=this;e.lockToScrollPos=[e.$container.scrollLeft(),e.$container.scrollTop()];e.$container.on("mousewheel.disablescroll DOMMouseScroll.disablescroll touchmove.disablescroll",e._handleWheel);e.$container.on("scroll.disablescroll",function(){e._handleScrollbar.call(e)});e.opts.handleKeys&&e.$document.on("keydown.disablescroll",function(t){e._handleKeydown.call(e,t)})};n.undo=function(){var e=this;e.$container.off(".disablescroll");e.opts.handleKeys&&e.$document.off(".disablescroll")};n._handleWheel=function(e){e.preventDefault()};n._handleScrollbar=function(){this.$container.scrollLeft(this.lockToScrollPos[0]);this.$container.scrollTop(this.lockToScrollPos[1])};n._handleKeydown=function(e){for(var t=0;t<this.opts.scrollEventKeys.length;t++)if(e.keyCode===this.opts.scrollEventKeys[t]){e.preventDefault();return}};e.fn.disablescroll=function(e){!t&&(typeof e=="object"||!e)?t=new r(this,e):t&&t[e]&&t[e].call(t)};window.UserScrollDisabler=r})(jQuery); var $nonScrollable = $("#non-scrollable") $nonScrollable.disablescroll(); $("button").on("click", function() { $nonScrollable.disablescroll("undo"); });
实例:http://jsfiddle.net/5s01jg4s/
3. 自定义用法,简单的使用 ($left_column 和 $right_column 为页面左右栏):
$left_column.hover(function(){$right_column.bind("mousewheel", function(e) { e.preventDefault(); return false; });},function(){$right_column.unbind("mousewheel");}); $right_column.hover(function(){$left_column.bind("mousewheel", function(e) { e.preventDefault(); return false; });},function(){$left_column.unbind("mousewheel");});
原文:jquery:临时禁止鼠标滚动 How to disable scrolling temporarily?
相关推荐
This shows how to disable control alt and delete by tricking the computer into thinking that the screensaver is running.
This is a straight forward example of how to disable any Win95/98 window..
As there are a lot questions about "how to disable home button in android?" on Stack Overflow, such as how to disable home button in android? Android - Is It possible to disable the click of home ...
后仿
jQuery 适合 用于扩展元素高度的轻量级 jQuery 插件 用法 $('#some_element').fit(options); 选项(带有默认值) width: false, // enable/disable width fitting height: false, // enable/disable height ...
如何关闭QC3.0
Severity Code Description ... To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 解决方案:更改预处理定义 右击项目名,选择Properties 在c/c++下选择Preprocessor 点击图
$("#amazon_scroller3").amazon_scroller({ scroller_title_show: 'enable',//enable disable scroller_time_interval: '3000', scroller_window_background_color: "#FFF", scroller_window_padding: '10', ...
1. How to change different panel? Simply remove the marked tag the panel you want to use and mark the original one in the "System.h". 2. How to change different IC (T100A/T101/T101A/T102)? Just ...
WordPress的插件:google字体插件-disable-google-fonts 解压后,请将目录名称:wordpress1,修改为:disable-google-fonts
jQuery blockUI plugin Version 2.39 (23-MAY-2011) Demos: $(document).ready(function() { $('#demo1').click(function() { $.blockUI({ message: $('#loginForm') }); setTimeout($.unblockUI, 2000); ...
在IE浏览器中,给select的options设置 disable属性 是没用的。 必须采用一定手段才可以解决这个问题。当然原理就是记住上次选中的 option。 this.selectedIndex 就派上用场了。 需要刷新下才可以看到效果,因为输出...
此adb中无adb disable-verity命令,如果在cmd中输入以上命令会报 /system/bin/sh: disable-verity: not found 的错误。具体可看本人的文章 ”/system/bin/sh: disable-verity: not found 的解决方案“ 【使用方式】...
单击使用jQuery的号召性用语后,禁用/启用元素 disableClicks的目的是修复在某些浏览器(例如Google Chrome)中或在互联网连接速度较慢时保存表单时的不当行为。 在这种情况下,当最终用户多次按下提交按钮(或其他...
WizMouse Enabled:启用WizMouse Left click tray icon to enable/disable:左键点击图标开启/关闭 Start with Windows:开机启动 ...Bring Scrolling windows to foreground:当滚动下方窗口时,将窗口切换到上方窗
在jquery中可以使用attr()函数修改按钮的disable属性 $(“#test”).attr(‘disabled’,false); jquery 控制button的disabled属性 代码如下: $(‘#button’).attr(‘disabled’,”true”);添加disabled属性 $(‘#...
eslint-plugin-disable 使用文件路径模式和内联注释禁用ESLint插件..这意味着所有禁用的插件的错误和警告都不会出现在ESLint报告中。 示例:内联注释: /* eslint-plugin-disable react */function greet ( name ) {...
再次单击并重新启用所有以前禁用的扩展。 有时,您只需要暂时禁用chrome扩展程序即可。只需单击一下,此扩展程序便可以做到这一点。更好的是,它可以记住先前启用了哪些扩展,并且只需单击一下即可再次启用它们。...
IIC: DISABLE PFD: DISABLE PWM: DISABLE WDT: ENABLE CLRWDT: ONE WDT CLOCK SOURCE: T1 WDT TIME OUT SELECT: WDT CLOCK SOURCE/32768 LVR: DISABLE OSC: CRYSTAL SYSVOLT: 3.0V SYSFRAG: 4000KHZ ...