Используется на сайте вот такой код для плавного скролла по якорю
$('a[href*="#"]')
.not('[href="#"]')
.not('[href="#0"]').on('click', function(event) {
if ($(this).closest('ul').hasClass('story-anchors')) {
var windowHeight = $(window).height(),
countWindows = $(this).attr("data-windowCount");
clickAnchor(this, 0, 0, 1200, 0, windowHeight, countWindows);
} else if ($(this).closest('ul').hasClass('anchors-list')) {
var navHeight = $('.anchors-list').outerHeight() - 2;
clickAnchor(this, navHeight, 1, 500, 1, 0, 0);
} else {
clickAnchor(this, 0, 1, 500, 1, 0, 0);
}
});
function clickAnchor(ob, heightNav, attrHeaderHeight, speed, attrTop, windowHeight, countWindows) {
event.preventDefault();
var headerHeight = $('.header').height();
$('html, body').animate({
scrollTop: (windowHeight * countWindows) + ($($.attr(ob, 'href')).offset().top * attrTop) - (headerHeight * attrHeaderHeight) - heightNav
}, speed);
}
на одной из страниц идет ссылка на якорь, который находится на другой странице. При клике на такую ссылку в консоли выбивает:
Uncaught TypeError: Cannot read property 'top' of undefined
Функция в данном случае использует последний else.
Это как-то можно пофиксить?