Why does a fixed background-image move when scrolling on IE?

前端 未结 11 1380
时光取名叫无心
时光取名叫无心 2020-12-29 06:37

I\'m trying to make background-image fixed.

As you see in my blog, the background-image is moving when scrolling on IE 11.

How can

11条回答
  •  独厮守ぢ
    2020-12-29 07:12

    Here is a way to handle PageUP and PageDOWN keyS based on the previous answers :

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

提交回复
热议问题