简体   繁体   中英

How to disable smooth scrolling in IE11

IE's smooth scrolling is causing my app behave strange (scroll events are fired with a small delay).

Is there a way to completely disable smooth scrolling in IE11 using CSS or Javascript?

IE's smooth scrolling feature is turned on for all windows 8 users of IE11.

You can disable it by going to Internet options, Advanced, and uncheck use smooth scrolling. And it resolves the problem. But all users of your site will not do that. So I highly recommend you not disabling it. Try to develop on the same machines/browsers that your users will use. Otherwise you will have inconsistencies with your users of your site. I also recommend to NEVER change the default browser settings, for the same reason.

Here is a JS fix.

Fiddle

if(navigator.userAgent.match(/Trident\/7\./)) {
    $('body').on("mousewheel", function (event) {
        event.preventDefault();
        var wd = event.wheelDelta;
        var csp = window.pageYOffset;
        window.scrollTo(0, csp - wd);
    });
}

This code will handle every scroll type (mouse and keyboard (PageUP, PageDOWN, Up, Down)):

if(navigator.userAgent.match(/Trident\/7\./)) { // if IE
    $('body').on("mousewheel", function () {
        // remove default behavior
        event.preventDefault(); 

        //scroll without smoothing
        var wheelDelta = event.wheelDelta;
        var currentScrollPosition = window.pageYOffset;
        window.scrollTo(0, currentScrollPosition - wheelDelta);
    });
    $('body').keydown(function (e) {
        var currentScrollPosition = window.pageYOffset;

        switch (e.which) {
            case 33: // page up
                e.preventDefault(); // prevent the default action (scroll / move caret)
                window.scrollTo(0, currentScrollPosition - 600);
                break;
            case 34: // page down
                e.preventDefault(); // prevent the default action (scroll / move caret)
                window.scrollTo(0, currentScrollPosition + 600);
                break;
            case 38: // up
                e.preventDefault(); // prevent the default action (scroll / move caret)
                window.scrollTo(0, currentScrollPosition - 120);
                break;
            case 40: // down
                e.preventDefault(); // prevent the default action (scroll / move caret)
                window.scrollTo(0, currentScrollPosition + 120);
                break;
            default: return; // exit this handler for other keys
        } 
    });

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM