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

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -