-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmoothScroll.js
39 lines (30 loc) · 1.05 KB
/
smoothScroll.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
smoothScroll = function(){
//smooth scroll if not clicked on the carousel
$(function() {
//smooth scroll to links on the same page
$('a[href*=#]:not([href=#carousel])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
//smooth scroll with #onload ** must be below page function
if(window.location.hash) {
var hash = window.location.hash.substring(1);
console.log(hash);
hash = $('#' + hash);
console.log(hash);
$('html,body').animate({
scrollTop: hash.offset().top
}, 1000);
return false;
}
//smoothScroll on same page links
}