Disable ctrl + mouse scroll on a webpage
How can I disable CTRL + mouse scro开发者_如何学编程ll on web page with jquery?
I want to disable zoom in and zoom out on my web page!
Yes you can do this :
$(window).keydown(function(event)
{
if((event.keyCode == 107 && event.ctrlKey == true) || (event.keyCode == 109 && event.ctrlKey == true))
{
event.preventDefault();
}
$(window).bind('mousewheel DOMMouseScroll', function(event)
{
if(event.ctrlKey == true)
{
event.preventDefault();
}
});
});
This will only work for Firefox, Chrome and Opera. It will not work with Internet Explorer.
This is not possible.
Instead, you should design your page to support zoom.
you can do this, i've tested on chrome、filefox and ie. it work well
(function () {
/**
* Main stopscrollwheelzoom constructor
*/
let SSWZ = function () {
/**
* Handler for scroll- control must be pressed.
* @param e
*/
this.keyScrollHandler = function (e) {
if (e.ctrlKey) {
e.preventDefault();
return false;
}
}
};
if (window === top) {
let sswz = new SSWZ();
window.addEventListener('wheel', sswz.keyScrollHandler, { passive: false });
}
})();
精彩评论