Last active
March 31, 2021 07:14
-
-
Save divienginesupport/d94da1ea1c51ef5d2c29c9f2b9553a3e to your computer and use it in GitHub Desktop.
This adds a class to the Divi header that changes the background color on scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
jQuery(document).ready(function( $ ) { // When jQuery is ready | |
function check_from_top_de(){ // Create our function | |
var scroll = $(window).scrollTop(); // Check scroll distance | |
if (scroll >= 300) { // If it is equal or more than 300 - you can change this to what you want | |
$("#main-header").addClass("change-bg-color"); // Add custom class to body which will change the color | |
} else { | |
$("#main-header").removeClass("change-bg-color"); // When scrolled to the top, remove the class which changes the color back | |
} | |
} | |
check_from_top_de(); // On load, run the function | |
$(window).scroll(function() { // When scroll - run function | |
check_from_top_de(); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment