mirror of
https://github.com/gcushen/hugo-academic.git
synced 2025-07-26 19:15:16 +02:00
Fix smooth scrolling for Home and Back to Top links
This commit is contained in:
parent
e59e1382e5
commit
1e3879e5a7
3 changed files with 32 additions and 14 deletions
|
@ -1,6 +1,4 @@
|
|||
# Website URL (e.g. http://www.example.com/)
|
||||
baseurl = "/"
|
||||
|
||||
baseurl = "http://replace-this-with-your-website-url.com/"
|
||||
title = "Academic Theme"
|
||||
copyright = "© 2016 Your Name"
|
||||
languageCode = "en-us"
|
||||
|
@ -86,7 +84,7 @@ googleAnalytics = ""
|
|||
|
||||
[[menu.main]]
|
||||
name = "Home"
|
||||
url = "#"
|
||||
url = "#top"
|
||||
weight = 1
|
||||
|
||||
[[menu.main]]
|
||||
|
|
|
@ -26,4 +26,4 @@
|
|||
<title>{{ if not .IsHome }}{{ .Title }} | {{ end }}{{ .Site.Title }}</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<body id="top">
|
||||
|
|
|
@ -9,10 +9,12 @@
|
|||
* Add smooth scrolling to all links inside the main navbar.
|
||||
* --------------------------------------------------------------------------- */
|
||||
|
||||
$("#navbar-main li.nav-item a").on('click', function(event){
|
||||
$('#navbar-main li.nav-item a').on('click', function(event){
|
||||
|
||||
// Store requested URL hash.
|
||||
var hash = this.hash;
|
||||
|
||||
// If we are on the homepage and the navigation bar link is to a homepage section.
|
||||
if( hash && $(hash).length && ($("#homepage").length > 0)){
|
||||
// Prevent default click behavior
|
||||
event.preventDefault();
|
||||
|
@ -25,11 +27,29 @@
|
|||
scrollTop: $(hash).offset().top - navbarHeight
|
||||
}, 800, function () {
|
||||
// Add hash (#) to URL once finished scrolling to hash position
|
||||
if (hash == "#top"){
|
||||
window.location.hash = ""
|
||||
}else {
|
||||
window.location.hash = hash;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
* Smooth scrolling for Back To Top link.
|
||||
* --------------------------------------------------------------------------- */
|
||||
|
||||
$('#back_to_top').on('click', function(event){
|
||||
event.preventDefault();
|
||||
|
||||
$('html, body').animate({
|
||||
'scrollTop': 0
|
||||
}, 800, function(){
|
||||
window.location.hash = ""
|
||||
});
|
||||
});
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
* Smooth scrolling for mouse wheel.
|
||||
* --------------------------------------------------------------------------- */
|
||||
|
@ -69,9 +89,9 @@
|
|||
}
|
||||
});
|
||||
|
||||
/* --------------------------------------------------------------------------------------------------------------------------
|
||||
* On Window Load.
|
||||
* ----------------------------------------------------------------------------------------------------------------------- */
|
||||
/* ---------------------------------------------------------------------------
|
||||
* On window load.
|
||||
* --------------------------------------------------------------------------- */
|
||||
|
||||
$(window).load(function(){
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue