Skip to content

Commit

Permalink
when determining navbar colour, add a small delay to make sure it was…
Browse files Browse the repository at this point in the history
… painted
  • Loading branch information
daattali authored Aug 22, 2020
1 parent b76c4fa commit a04d8bb
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions assets/js/beautifuljekyll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down

0 comments on commit a04d8bb

Please sign in to comment.