B
B
butize2020-04-29 12:33:25
JavaScript
butize, 2020-04-29 12:33:25

Why doesn't the code work in Internet Explorer 11 and Edge?

Why doesn't this code work in Internet Explorer 11?

var anchors = $('a[href*="#product"]');

        for (var anchor of anchors) {
            $(anchor).click(function(evt) {
                evt.preventDefault();
                const blockID = $(anchor).attr('href').substr(8);
                const headerHeight = $("header.page-header").height();
                const elemCoord = $("#product"+blockID).offset().top;
                const trueCoord = elemCoord - headerHeight;
                $("html, body").animate({scrollTop: trueCoord+"px"}, 800);
            });   
        }

        var sections3 = $('section[id*="product"]'),
            nav3 = $('.pagination-container > ol'),
            header3 = $('header.page-header'), 
            nav_height3 = header3.outerHeight();

        $(window).on('scroll', function () {
            var cur_pos = $(this).scrollTop();
          
            sections3.each(function() {
                var top = $(this).offset().top - nav_height3,
                    bottom = top + $(this).outerHeight();
                var currentId = $(this).attr('id');
                if (cur_pos >= top) {
                    nav3.find('li').removeClass('active');
                    sections3.removeClass('active');
                    $(this).addClass('active');
                    nav3.find('a[href="#'+currentId+'"]').parent('li').addClass('active');
                }
            });
        });

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav Boychenko, 2020-04-29
@butize

Well, probably because https://caniuse.com/#search=for...of ?

T
ThunderCat, 2020-04-29
@ThunderCat

there seems to be a console there, check at what stage the script does not work for you, arrange the logs in the course of execution, track the breakpoint. Classic or...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question