svyatogor92
svyatogor92

Reputation: 113

JQuery .animate() not working on IE

My JQuery .animate() function seems to not working on IE. Could You please help me transform it to a pure JS solution?

var brandLink = $('#brand');
var pageTop = $('#page-top');
var navLinks = $('.nav-link');
var offerSection = $('#offer');
var techSection = $('#tech');
var portfolioSection = $('#portfolio');
var contactSection = $('#contact');
var moreBtn = $('.more-button');

navLinks.eq(0).click(() => {
    $('html, body').animate({
        scrollTop: pageTop.offset().top
    }, 500);
});

As You can see this is used for scrolling page to propper section/page-top in One page website.

Can someone explain why animate() doesn't work on IE?

Upvotes: 1

Views: 171

Answers (2)

rabsom
rabsom

Reputation: 859

Depending on the version of IE you need to support, have a look at this site. You will find some generic turnarounds that might help.

Also have a look at this (adding a preventDefault(); to make sure the script is working properly).

Upvotes: 0

noa-dev
noa-dev

Reputation: 3641

Quick shot, try:

var brandLink = $('#brand');
var pageTop = $('#page-top');
var navLinks = $('.nav-link');
var offerSection = $('#offer');
var techSection = $('#tech');
var portfolioSection = $('#portfolio');
var contactSection = $('#contact');
var moreBtn = $('.more-button');

navLinks.eq(0).click(function(e) {
    e.preventDefault(); // to prevent native behaviour of the thing you press
    $('html, body').animate({
        scrollTop: pageTop.offset().top
    }, 500);
});

Upvotes: 1

Related Questions