Scroll progress bar
This commit is contained in:
parent
eb84edae6d
commit
9f7c0e30e2
5 changed files with 130 additions and 27 deletions
|
@ -151,7 +151,7 @@ body {
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
font-size: 1.3rem;
|
font-size: 1.2rem;
|
||||||
overflow-y: hidden;
|
overflow-y: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,6 +160,7 @@ body {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
padding-bottom: 80px;
|
padding-bottom: 80px;
|
||||||
|
letter-spacing: 0.4px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
overflow-y: hidden;
|
overflow-y: hidden;
|
||||||
|
@ -181,6 +182,7 @@ The knock-on effect of this is ugly browser-scroll bars at the bottom, so 80px o
|
||||||
display: block;
|
display: block;
|
||||||
margin-right: 24px;
|
margin-right: 24px;
|
||||||
font-size: 1.7rem;
|
font-size: 1.7rem;
|
||||||
|
line-height: 1em;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
letter-spacing: -0.5px;
|
letter-spacing: -0.5px;
|
||||||
|
@ -1120,7 +1122,7 @@ Super neat trick courtesy of @JoelDrapper
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
height: 48px;
|
height: 60px;
|
||||||
border-bottom: rgba(0,0,0,0.06) 1px solid;
|
border-bottom: rgba(0,0,0,0.06) 1px solid;
|
||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
@ -1138,10 +1140,10 @@ Super neat trick courtesy of @JoelDrapper
|
||||||
}
|
}
|
||||||
|
|
||||||
.floating-header-logo {
|
.floating-header-logo {
|
||||||
margin: 0 0 0 15px;
|
margin: 0 0 0 20px;
|
||||||
font-size: 1.5rem;
|
font-size: 1.7rem;
|
||||||
line-height: 1.3em;
|
line-height: 1em;
|
||||||
letter-spacing: -0.5px;
|
letter-spacing: -1px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
@ -1152,7 +1154,6 @@ Super neat trick courtesy of @JoelDrapper
|
||||||
align-items: center;
|
align-items: center;
|
||||||
color: var(--darkgrey);
|
color: var(--darkgrey);
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
line-height: 1em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.floating-header-logo a:hover {
|
.floating-header-logo a:hover {
|
||||||
|
@ -1161,7 +1162,7 @@ Super neat trick courtesy of @JoelDrapper
|
||||||
|
|
||||||
.floating-header-logo img {
|
.floating-header-logo img {
|
||||||
max-height: 20px;
|
max-height: 20px;
|
||||||
margin-right: 10px;
|
margin: 0 10px 1px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.floating-header-divider {
|
.floating-header-divider {
|
||||||
|
@ -1173,7 +1174,7 @@ Super neat trick courtesy of @JoelDrapper
|
||||||
flex: 1;
|
flex: 1;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 1.5rem;
|
font-size: 1.7rem;
|
||||||
line-height: 1.3em;
|
line-height: 1.3em;
|
||||||
color: #2e2e2e;
|
color: #2e2e2e;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
@ -1222,9 +1223,9 @@ Super neat trick courtesy of @JoelDrapper
|
||||||
.floating-header-share-tw,
|
.floating-header-share-tw,
|
||||||
.floating-header-share-fb {
|
.floating-header-share-fb {
|
||||||
display: block;
|
display: block;
|
||||||
width: 48px;
|
width: 60px;
|
||||||
height: 48px;
|
height: 60px;
|
||||||
line-height: 45px;
|
line-height: 48px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
|
@ -1239,8 +1240,51 @@ Super neat trick courtesy of @JoelDrapper
|
||||||
background: #005e99;
|
background: #005e99;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.progress {
|
||||||
|
position: absolute;
|
||||||
|
bottom: -1px;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 1px;
|
||||||
|
border: none;
|
||||||
|
color: var(--blue);
|
||||||
|
background: transparent;
|
||||||
|
appearance: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress::-webkit-progress-bar {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress::-webkit-progress-value {
|
||||||
|
background-color: var(--blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-container {
|
||||||
|
width: 100%;
|
||||||
|
background-color: transparent;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
height: 1px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-bar {
|
||||||
|
background-color: var(--blue);
|
||||||
|
width: 50%;
|
||||||
|
display: block;
|
||||||
|
height: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 900px) {
|
@media (max-width: 900px) {
|
||||||
.floating-header { height: 40px; }
|
.floating-header { height: 40px; }
|
||||||
|
.floating-header-logo img { margin-bottom: 0; }
|
||||||
|
.floating-header-title,
|
||||||
|
.floating-header-logo {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
}
|
||||||
.floating-header-share-tw,
|
.floating-header-share-tw,
|
||||||
.floating-header-share-fb {
|
.floating-header-share-fb {
|
||||||
height: 40px;
|
height: 40px;
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -20,4 +20,9 @@
|
||||||
{{> "icons/facebook"}}
|
{{> "icons/facebook"}}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
<progress class="progress" value="0">
|
||||||
|
<div class="progress-container">
|
||||||
|
<span class="progress-bar"></span>
|
||||||
|
</div>
|
||||||
|
</progress>
|
||||||
</div>
|
</div>
|
||||||
|
|
80
post.hbs
80
post.hbs
|
@ -162,22 +162,76 @@ into the {body} of the default.hbs template --}}
|
||||||
{{!-- The #contentFor helper here will send everything inside it up to the matching #block helper found in default.hbs --}}
|
{{!-- The #contentFor helper here will send everything inside it up to the matching #block helper found in default.hbs --}}
|
||||||
{{#contentFor "scripts"}}
|
{{#contentFor "scripts"}}
|
||||||
<script>
|
<script>
|
||||||
$(function() {
|
// TODO: SOMEONE PLEASE REFACTOR THIS SHITSHOW? 😭
|
||||||
var $postContent = $(".post-full-content");
|
$(document).ready(function(){
|
||||||
$postContent.fitVids();
|
$(function() {
|
||||||
|
// Start fitVids
|
||||||
|
var $postContent = $(".post-full-content");
|
||||||
|
$postContent.fitVids();
|
||||||
|
// End fitVids
|
||||||
|
|
||||||
$(window).scroll(function() {
|
// Start show/hide floating header
|
||||||
var header = $(".floating-header");
|
$(window).scroll(function() {
|
||||||
var title = $(".post-full-title");
|
var header = $(".floating-header");
|
||||||
var trigger = title.offset().top;
|
var title = $(".post-full-title");
|
||||||
var scroll = $(window).scrollTop();
|
var trigger = title.offset().top;
|
||||||
|
var scroll = $(window).scrollTop();
|
||||||
|
|
||||||
if (scroll >= trigger + title.height() + 35 ) {
|
if (scroll >= trigger + title.height() + 35 ) {
|
||||||
header.addClass("floating-active");
|
header.addClass("floating-active");
|
||||||
} else {
|
} else {
|
||||||
header.removeClass("floating-active");
|
header.removeClass("floating-active");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
// End show/hide floating header
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Start scroll-progress bar
|
||||||
|
// Source: https://codepen.io/pankajparashar/pen/towxF
|
||||||
|
// Markup: floating-header.hbs
|
||||||
|
var getMax = function(){
|
||||||
|
return $(document).height() - $(window).height();
|
||||||
|
}
|
||||||
|
|
||||||
|
var getValue = function(){
|
||||||
|
return $(window).scrollTop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if('max' in document.createElement('progress')){
|
||||||
|
var progressBar = $('progress');
|
||||||
|
progressBar.attr({ max: getMax() });
|
||||||
|
|
||||||
|
$(document).on('scroll', function(){
|
||||||
|
progressBar.attr({ value: getValue() });
|
||||||
|
});
|
||||||
|
|
||||||
|
$(window).resize(function(){
|
||||||
|
progressBar.attr({ max: getMax(), value: getValue() });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var progressBar = $('.progress-bar'),
|
||||||
|
max = getMax(),
|
||||||
|
value, width;
|
||||||
|
|
||||||
|
var getWidth = function(){
|
||||||
|
value = getValue();
|
||||||
|
width = (value/max) * 100;
|
||||||
|
width = width + '%';
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
var setWidth = function(){
|
||||||
|
progressBar.css({ width: getWidth() });
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).on('scroll', setWidth);
|
||||||
|
$(window).on('resize', function(){
|
||||||
|
max = getMax();
|
||||||
|
setWidth();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// End scroll-progress bar
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{{/contentFor}}
|
{{/contentFor}}
|
||||||
|
|
Loading…
Reference in a new issue