I know there have been a variety of answers to similar questions, but my JS skills are so poor I cannot really get the answers to work in my specific example. I have the following script on my WordPress site which tells the navigation bar to change color once it hits the #startchange CSS ID when scrolling down the page.
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');
}
});
});
This works perfectly on the page that I want it implemented on (the landing page) but for the blog posts pages, the background is white and therefore the navbar is invisible. What modification do I need to do to this script to tell it to only function on the landing page, or alternatively what can be done to the script to tell it that when it is a blog post page that a certain CSS class be applied to it?
scrollevent handler.