Solo
Solo

Reputation: 6977

Problems with IE and Edge, probably scroll smoothing

I have fixed header that animates up (by the height of header) if scrolled down and reappears when scrolled up.

I had header jumping issues before with IE and I used this:

//IE jumping fixed elements fix
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);
    });
}

It shows JS error that Object doesn't support property or method 'preventDefault' with every scroll but it somehow works.

But now with new Edge, even this doesn't work (I tried /Edge\/12./). Everything works nicely with Firefox and Chrome.

Upvotes: 0

Views: 1621

Answers (1)

Sampson
Sampson

Reputation: 268492

You're attempting to call .preventDefault off of event, but event isn't in your handler's list of arguments. As such, event is either defined outside of this scope, or undefined. Either way, it's not what you're expecting.

One other suggestion (in particular for older versions of IE and older hardware) would be to throttle this method so that it's not running dozens of times each second.

Microsoft Edge should function like Chrome and Firefox. If it's not, please direct me to a resource that shows the issue and I'll gladly file a bug for the team to evaluate.

Upvotes: 1

Related Questions