when determining navbar colour, add a small delay to make sure it was painted

This commit is contained in:
Dean Attali 2020-08-21 23:05:37 -04:00 committed by GitHub
parent b76c4fa1b3
commit a04d8bb1b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,16 +6,7 @@ var BeautifulJekyllJS = {
numImgs : null, numImgs : null,
init : function() { init : function() {
// Set the navbar-dark/light class based on its background color setTimeout(BeautifulJekyllJS.initNavbar, 10);
const rgb = $('.navbar').css("background-color").replace(/[^\d,]/g,'').split(",");
const brightness = Math.round(( // http://www.w3.org/TR/AERT#color-contrast
parseInt(rgb[0]) * 299 +
parseInt(rgb[1]) * 587 +
parseInt(rgb[2]) * 114
) / 1000);
if (brightness <= 125) {
$(".navbar").removeClass("navbar-light").addClass("navbar-dark");
}
// Shorten the navbar after scrolling a little bit down // Shorten the navbar after scrolling a little bit down
$(window).scroll(function() { $(window).scroll(function() {
@ -38,6 +29,19 @@ var BeautifulJekyllJS = {
BeautifulJekyllJS.initImgs(); BeautifulJekyllJS.initImgs();
}, },
initNavbar : function() {
// Set the navbar-dark/light class based on its background color
const rgb = $('.navbar').css("background-color").replace(/[^\d,]/g,'').split(",");
const brightness = Math.round(( // http://www.w3.org/TR/AERT#color-contrast
parseInt(rgb[0]) * 299 +
parseInt(rgb[1]) * 587 +
parseInt(rgb[2]) * 114
) / 1000);
if (brightness <= 125) {
$(".navbar").removeClass("navbar-light").addClass("navbar-dark");
}
},
initImgs : function() { initImgs : function() {
// If the page was large images to randomly select from, choose an image // If the page was large images to randomly select from, choose an image
if ($("#header-big-imgs").length > 0) { if ($("#header-big-imgs").length > 0) {