link target with absolute path on same page scrolls

This commit is contained in:
Arvind Tiwari 2018-03-22 02:43:53 +05:30
parent 50312db5f8
commit f1a77d65c4

View file

@ -104,21 +104,33 @@
});
$('.url').click(function(event) {
event.preventDefault();
var href = $(this).attr('href');
var $this = $(this);
var href = $this.attr('href');
$('.navbar-collapse').removeClass('in');
$('.navbar-collapse').addClass('collapsing');
if (href[0] === "#") {
if ($(href).length) {
$('html, body').animate({
scrollTop: $(href).offset().top - 50
}, 1000);
}
scrollToElement(href);
} else if (href) {
var path = $(this).prop('href').split('#');
var currentPath = window.location.origin + window.location.pathname;
if (!path[1]) {
window.location = href;
} else if (currentPath == path[0]) {
scrollToElement('#' + path[1]);
}
}
});
}
function scrollToElement(el) {
var $el = $(el);
if ($el.length) {
$('html, body').animate({
scrollTop: $el.offset().top - 50
}, 1000);
}
}
function verifiedUrl() {
if (window.location.href.indexOf('#success') > -1) {
form_success();