From a04d8bb1b645101723e441c8fff8f65f775fdffe Mon Sep 17 00:00:00 2001 From: Dean Attali Date: Fri, 21 Aug 2020 23:05:37 -0400 Subject: [PATCH] when determining navbar colour, add a small delay to make sure it was painted --- assets/js/beautifuljekyll.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/assets/js/beautifuljekyll.js b/assets/js/beautifuljekyll.js index f6319d01cdfc..9c5ca3859f23 100644 --- a/assets/js/beautifuljekyll.js +++ b/assets/js/beautifuljekyll.js @@ -6,16 +6,7 @@ var BeautifulJekyllJS = { numImgs : null, init : 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"); - } + setTimeout(BeautifulJekyllJS.initNavbar, 10); // Shorten the navbar after scrolling a little bit down $(window).scroll(function() { @@ -38,6 +29,19 @@ var BeautifulJekyllJS = { 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() { // If the page was large images to randomly select from, choose an image if ($("#header-big-imgs").length > 0) {