Skip to content

Instantly share code, notes, and snippets.

@divienginesupport
Last active March 30, 2021 18:12
Show Gist options
  • Save divienginesupport/b6851103141499f2a6e729e5e89ef456 to your computer and use it in GitHub Desktop.
Save divienginesupport/b6851103141499f2a6e729e5e89ef456 to your computer and use it in GitHub Desktop.
Sample jQuery that can be added to Divi
<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
$("#your-target-element").addClass("class-to-be-added"); // Add custom class to body
} else {
$("#your-target-element").removeClass("class-that-we-added"); // When scrolled to the top, remove the class
}
}
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