mirror of
https://git.adityakumar.xyz/hugo-theme-introduction.git
synced 2024-11-08 14:49:43 +00:00
Linkify headings, use scroll-behavior
- Uses the scroll-behavior property to achieve smooth scrolling with less JS - Solves anchor link bugs - Linkifies headings in posts so they can be easily hyperlinked to directly
This commit is contained in:
parent
89b8d152a9
commit
8a9baff968
6 changed files with 40 additions and 40 deletions
|
@ -1,52 +1,35 @@
|
||||||
// Nav burger animation
|
// Nav burger animation
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
// Get all "navbar-burger" elements
|
// Get all "navbar-burger" elements
|
||||||
var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll(".navbar-burger"), 0);
|
var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0)
|
||||||
// Check if there are any navbar burgers
|
// Check if there are any navbar burgers
|
||||||
if ($navbarBurgers.length > 0) {
|
if ($navbarBurgers.length > 0) {
|
||||||
// Add a click event on each of them
|
// Add a click event on each of them
|
||||||
$navbarBurgers.forEach(function ($el) {
|
$navbarBurgers.forEach(function ($el) {
|
||||||
$el.addEventListener("click", function () {
|
$el.addEventListener('click', function () {
|
||||||
// Get the target from the "data-target" attribute
|
// Get the target from the "data-target" attribute
|
||||||
var target = $el.dataset.target;
|
var target = $el.dataset.target
|
||||||
var $target = document.getElementById(target);
|
var $target = document.getElementById(target)
|
||||||
// Toggle the class on both the "navbar-burger" and the "navbar-menu"
|
// Toggle the class on both the "navbar-burger" and the "navbar-menu"
|
||||||
$el.classList.toggle("is-active");
|
$el.classList.toggle('is-active')
|
||||||
$target.classList.toggle("is-active");
|
$target.classList.toggle('is-active')
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// Bitty scrolling links script
|
|
||||||
$("a[href^=\"#\"]").click(function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
//BUG fix: https://github.com/victoriadrake/hugo-theme-introduction/issues/108
|
|
||||||
//
|
|
||||||
//let's get the right attribute `id` of the heading
|
|
||||||
v = e.target.href.replace(/http.*#/, '')
|
|
||||||
id = decodeURI(v)
|
|
||||||
|
|
||||||
$("html, body").animate({
|
|
||||||
//scrollTop: $(document.getElementById(this.hash.substr(1))).offset().top
|
|
||||||
scrollTop: $(document.getElementById(id)).offset().top
|
|
||||||
}, 500);
|
|
||||||
$("#nav-menu").removeClass("is-active");
|
|
||||||
return true;
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Modal closer
|
// Modal closer
|
||||||
$(".card").click(function () {
|
$('.card').click(function () {
|
||||||
$($(this).attr("data-target")).addClass("is-active");
|
$($(this).attr('data-target')).addClass('is-active')
|
||||||
$("html").addClass("modal-open");
|
$('html').addClass('modal-open')
|
||||||
});
|
})
|
||||||
$(".modal-close").click(function () {
|
$('.modal-close').click(function () {
|
||||||
$($(this).attr("data-target")).removeClass("is-active");
|
$($(this).attr('data-target')).removeClass('is-active')
|
||||||
$("html").removeClass("modal-open");
|
$('html').removeClass('modal-open')
|
||||||
});
|
})
|
||||||
$(document).keypress(function(e) {
|
$(document).keypress(function (e) {
|
||||||
if(e.which == 0) {
|
if (e.which === 0) {
|
||||||
$(".modal.is-active").removeClass("is-active");
|
$('.modal.is-active').removeClass('is-active')
|
||||||
$("html").removeClass("modal-open");
|
$('html').removeClass('modal-open')
|
||||||
}
|
}
|
||||||
});
|
})
|
|
@ -1,6 +1,9 @@
|
||||||
html, body
|
html, body
|
||||||
background-color: $background
|
background-color: $background
|
||||||
|
|
||||||
|
html
|
||||||
|
scroll-behavior: smooth
|
||||||
|
|
||||||
html.modal-open
|
html.modal-open
|
||||||
overflow: hidden
|
overflow: hidden
|
||||||
|
|
||||||
|
@ -32,6 +35,8 @@ a
|
||||||
|
|
||||||
h1, h2, .title, .subtitle
|
h1, h2, .title, .subtitle
|
||||||
color: $h-color
|
color: $h-color
|
||||||
|
& a
|
||||||
|
color: $h-color
|
||||||
|
|
||||||
.title
|
.title
|
||||||
font-weight: 400
|
font-weight: 400
|
||||||
|
|
|
@ -7058,6 +7058,9 @@ readers do not read off random characters that represent icons */
|
||||||
html, body {
|
html, body {
|
||||||
background-color: #ffffff; }
|
background-color: #ffffff; }
|
||||||
|
|
||||||
|
html {
|
||||||
|
scroll-behavior: smooth; }
|
||||||
|
|
||||||
html.modal-open {
|
html.modal-open {
|
||||||
overflow: hidden; }
|
overflow: hidden; }
|
||||||
|
|
||||||
|
@ -7089,6 +7092,8 @@ a {
|
||||||
|
|
||||||
h1, h2, .title, .subtitle {
|
h1, h2, .title, .subtitle {
|
||||||
color: #222222; }
|
color: #222222; }
|
||||||
|
h1 a, h2 a, .title a, .subtitle a {
|
||||||
|
color: #222222; }
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
font-weight: 400; }
|
font-weight: 400; }
|
||||||
|
|
4
exampleSite/resources/_gen/assets/sass/sass/style.sass_c66aa4270d2fff5f284b149c059dd5bc.content
generated
Normal file
4
exampleSite/resources/_gen/assets/sass/sass/style.sass_c66aa4270d2fff5f284b149c059dd5bc.content
generated
Normal file
File diff suppressed because one or more lines are too long
1
exampleSite/resources/_gen/assets/sass/sass/style.sass_c66aa4270d2fff5f284b149c059dd5bc.json
generated
Normal file
1
exampleSite/resources/_gen/assets/sass/sass/style.sass_c66aa4270d2fff5f284b149c059dd5bc.json
generated
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"Target":"css/main.min.f91a9b569d2964898b50e2f66e41e1da8ca0794cfd6910f7d62ea94dbee45533.css","MediaType":"text/css","Data":{"Integrity":"sha256-+RqbVp0pZImLUOL2bkHh2oygeUz9aRD31i6pTb7kVTM="}}
|
2
layouts/_default/_markup/render-heading.html
Normal file
2
layouts/_default/_markup/render-heading.html
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
<h{{ .Level }} id="{{ .Anchor | safeURL }}" class="anchor-link"><a href="#{{ .Anchor | safeURL }}">{{ .Text | safeHTML }}</a></h{{ .Level }}>
|
Loading…
Reference in a new issue