svyatogor92 svyatogor92 - 8 months ago 60
Javascript Question

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?

Answer Source

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);
});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download