//Autoscrolling links
$.fn.isInViewport = function()
{
var elementTop = $(this).offset().top;
var elementBottom = elementTop + $(this).outerHeight();
var viewportTop = $(window).scrollTop();
var viewportBottom = viewportTop + $(window).height();
return elementBottom > viewportTop && elementTop < viewportBottom;
};
function scrollToTarget(target)
if( target && target.length && !target.isInViewport() )
$('html,body').animate({
scrollTop: target.offset().top - $("header").height()
}, 1000);
}
$(function ()
setTimeout(function ()
if (location.href.match("#to-") || $("#form-sent").length > 0)
$('html,body').scrollTop(0);
let target;
if (location.href.match("#to-"))
const arr = location.href.split("#to-");
const targetName = arr[1];
// Szukaj kolejno po name, id, data-scroll
target =
$("[name='" + targetName + "']").length ?
$("[name='" + targetName + "']")
: $("#" + targetName).length
? $("#" + targetName)
: $("[data-scroll='" + targetName + "']");
else
target = $("#form-sent");
scrollToTarget(target);
$("a[href*='#to-']:not([href='#'])").click(function(e)
if (location.pathname.replace(/^//,'') == this.pathname.replace(/^//,'') && location.hostname == this.hostname)
e.preventDefault();
const targetName = this.hash.replace("#to-", "");
let target = $("[name='" + targetName + "']");
if (target.length <= 0) target = $("#" + targetName);
if (target.length <= 0) target = $("[data-scroll='" + targetName + "']");
});