I have a navbar which has a transparant background when the site/a page opens. and transforms to a backround color when the next section reaches the top op the viewport:
var $window = $(window)
var $nav = $('nav')
var introTop = $('.services').offset().top
$window.scroll(function () {
var scrollTop = $window.scrollTop()
$nav.toggleClass('scrolled', scrollTop > introTop)
})
Hi @donboe, I wouldn’t change the image itself as this would cause a new request each time the image gets toggled; instead, just toggle the visibility like so:
@m3g4p0p Thank you for the reply. Could that be something with a fadeIn? And how would that look like in JS? And how should I do that in combination with the above function (yours )
As the .navbar-brand is inside the nav element, there are no JS adjustments necessary – you can use that .scrolled class to toggle other styles as well (and yes I recognised those lines). :-)
As for the fade effect, this can be achieved by absolutely positioning one image over the other and changing the opacity with a transition:
(This assumes both logos have the same size – otherwise you might need to position both absolutely and apply fixed dimensions to the container element.)