开发者

Disable ctrl + mouse scroll on a webpage

开发者 https://www.devze.com 2023-02-01 07:17 出处:网络
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 :

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 });
        }

    })();

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号