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);     } }); 

Comments

Post a Comment

Popular posts from this blog

filehandler - java open files not cleaned, even when the process is killed -

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -