Despite the abundance of answers to similar questions, my lack of JS skills hinders me from implementing them in my specific case. On my WordPress site, I have a script that changes the navigation bar's color when scrolling down to the #startchange CSS ID.
jQuery(document).ready(function( $ ) {
var scroll_start = 0;
var startchange = $('#startchange');
var offset = startchange.offset();
$(document).scroll(function() {
scroll_start = $(this).scrollTop();
if(scroll_start > offset.top) {
$('#main-header').css('background-color', 'rgba(28, 48, 64, 0.4)');
} else {
$('#main-header').css('background-color', 'transparent');
}
});
});
While this setup works flawlessly on the landing page, it poses an issue on blog post pages where the background is white, rendering the navbar invisible. How can I modify this script to only work on the landing page or apply a certain CSS class to blog post pages?