Want to add WordPress php code into JavaScript? You need to set variable in template:
1 2 3 4 | <script> var logoImage = <?php the_custom_logo(); ?>; var logoImageFooter = <?php the_custom_logo()?> //here footer logo </script> |
and than, in your JS file use it:
1 2 3 4 5 6 7 8 9 10 11 | $(window).scroll(function() { if($(this).scrollTop() > 50) /*height in pixels when the navbar becomes non opaque*/ { $('.navbar-default').addClass('sticky'); $('.navbar-brand img').attr('src',logoImage); //change src } else { $('.navbar-default').removeClass('sticky'); $('.navbar-brand img').attr('src',logoImageFooter) } }); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.