html - Trying to switch logo in header with jquery to add/remove class -
basically have header on site goes transparent background white when start scroll down. adds class header-fixed when starts scrolling. trying switch between 2 logos when header acive header-fixed or isn't. here jquery have right can't work:
$( document ).ready(function() { if( $('#masthead').hasclass('header-fixed') ) { $('.bdanzer-fixed').addclass('bdanzer-show'); } else { $('.bdanzer-fixed').removeclass('bdanzer-show'); } }); edit, adding html:
<img class="bdanzer-normal" src="https://dummytext"> <img class="bdanzer-fixed" src="https://dummytext">
could simplified using toggleclass function:
$(document).on('scroll', function(){ var hasclass = $('#masthead').hasclass('header-fixed')); $('.bdanzer-fixed').toggleclass('bdanzer-show', hasclass ); });
Comments
Post a Comment