Skip to content

Commit 9ca8ab0

Browse files
committed
solves dead link formation after adding smooth scrolling
1 parent 9f17ca9 commit 9ca8ab0

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

js/main.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,26 @@ jQuery(document).on('ready', function() {
5252
/* -------------------------------------
5353
ADD ANIMATIONS TO SECTION SCROLL
5454
-------------------------------------- */
55-
$('a[href*=\\#]').on('click', function(event){
56-
event.preventDefault();
57-
$('html,body').animate({scrollTop:$(this.hash).offset().top}, 700);
55+
function ea_scroll( hash ) {
56+
var target = $( hash );
57+
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
58+
if (target.length) {
59+
var top_offset = 0;
60+
$('html,body').animate({
61+
scrollTop: target.offset().top - top_offset
62+
}, 1000);
63+
return false;
64+
}
65+
}
66+
// -- Smooth scroll on pageload
67+
if( window.location.hash ) {
68+
ea_scroll( window.location.hash );
69+
}
70+
// -- Smooth scroll on click
71+
$('a[href*="#"]:not([href="#"]):not(.no-scroll)').click(function() {
72+
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') || location.hostname == this.hostname) {
73+
ea_scroll( this.hash );
74+
}
5875
});
5976

6077
/* -------------------------------------

0 commit comments

Comments
 (0)