wordpress - Switch logo using jQuery -
i using divi wordpress theme adds class .et-fixed-header
#main-header
while scrolling down. in header there logo wish change when there class .et-fixed-header
.
here jquery:
$(document).scroll(function () { if ($('#main-header').hasclass( 'et-fixed-header' )) { $('#logo').attr('src', 'new-img.png'); } });
my question is, how default logo when there no .et-fixed-header
in #main-header
. code replacing logo when scroll down not go default logo when scroll or in other words, when there no such class .et-fixed-header
in #main-header
. understand need place else
statement not sure of code. appreciative.
edit
the logo uploaded via theme options , not placing manually users
set original logo js variable , you'll have switch when #main-header
loses it's .et-fixed-header
class.
var origimage = ''; $(document).scroll(function () { if($('#logo').attr('src') != 'new-img.png') { origimage = $('#logo').attr('src') } if ($('#main-header').hasclass( 'et-fixed-header' )) { $('#logo').attr('src', 'new-img.png'); } else { $('#logo').attr('src', origimage); } });
Thanks for give us valuable information
ReplyDeleteContact WordPress Support
WordPress Support Service
Very Helpful. Thanks for such Information
ReplyDeleteWP Help
24x7 WP Support