I am trying to update the color of my navbar-toggle from white to black or black to white.
The issue arises when it reaches a specific div with a class like 'white' or 'black'; the color changes as soon as the scroll starts.
var stickyOffset = $(".navbar-toggle").offset();
var $contentDivs = $("section");
$(document).scroll(function() {
$contentDivs.each(function(k) {
var _thisOffset = $(this).offset();
var _actPosition = _thisOffset.top - $(window).scrollTop();
if (_actPosition < (stickyOffset.top + $('.navbar-toggle').height()/2) && _actPosition + $(this).height() - $('.navbar-toggle').height()/2 > 0) {
$(".bar1, .bar2, .bar3, .navbar-span").removeClass("white black").addClass($(this).hasClass("white") ? "white" : "black");
}
});
});
I have created a jsfiddle, but the change occurs too quickly and I'm unsure of what mistake I might be making.
http://jsfiddle.net/xarlyblack/8mn4bucw/
Thank you in advance! Best, Carl